use-node-info.ts 483 B

1234567891011121314151617181920
  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 parentNodeId = node?.parentId
  11. const parentNode = allNodes.find(n => n.id === parentNodeId)
  12. return {
  13. node,
  14. isInIteration,
  15. parentNode,
  16. }
  17. }
  18. export default useNodeInfo