Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

761 B
Raw Blame
import type { CommonNodeType } from '@/app/components/workflow/types'
import { useCallback, useEffect, useRef } from 'react'
import { useNodeDataUpdate } from '../../../hooks/use-node-data-update'

const useNodeCrud = <T>(id: string, data: CommonNodeType<T>) => {
  const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
  const updateRef = useRef(handleNodeDataUpdateWithSyncDraft)

  useEffect(() => {
    updateRef.current = handleNodeDataUpdateWithSyncDraft
  }, [handleNodeDataUpdateWithSyncDraft])

  const setInputs = useCallback(
    (newInputs: CommonNodeType<T>) => {
      updateRef.current({
        id,
        data: newInputs,
      })
    },
    [id],
  )

  return {
    inputs: data,
    setInputs,
  }
}

export default useNodeCrud