You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-nodes-interactions-without-sync.ts 620B

123456789101112131415161718192021222324252627
  1. import { useCallback } from 'react'
  2. import produce from 'immer'
  3. import { useStoreApi } from 'reactflow'
  4. export const useNodesInteractionsWithoutSync = () => {
  5. const store = useStoreApi()
  6. const handleNodeCancelRunningStatus = useCallback(() => {
  7. const {
  8. getNodes,
  9. setNodes,
  10. } = store.getState()
  11. const nodes = getNodes()
  12. const newNodes = produce(nodes, (draft) => {
  13. draft.forEach((node) => {
  14. node.data._runningStatus = undefined
  15. node.data._waitingRun = false
  16. })
  17. })
  18. setNodes(newNodes)
  19. }, [store])
  20. return {
  21. handleNodeCancelRunningStatus,
  22. }
  23. }