use-node-info.ts 538 B

1234567891011121314151617181920212223
  1. import { useStoreApi } from 'reactflow'
  2. const useNodeInfo = (nodeId: string) => {
  3. const store = useStoreApi()
  4. const {
  5. getNodes,
  6. } = store.getState()
  7. const allNodes = getNodes()
  8. const node = allNodes.find(n => n.id === nodeId)
  9. const isInIteration = !!node?.data.isInIteration
  10. const isInLoop = !!node?.data.isInLoop
  11. const parentNodeId = node?.parentId
  12. const parentNode = allNodes.find(n => n.id === parentNodeId)
  13. return {
  14. node,
  15. isInIteration,
  16. isInLoop,
  17. parentNode,
  18. }
  19. }
  20. export default useNodeInfo