#Updating nodes by custom events in custom nodes

1 messages · Page 1 of 1 (latest)

ivory sonnet
#

Hi, I would like to update node states (e.g., which node is selected, or some node data) when I click a button in my custom node. How can I do that?

Right now, I can only think about using React context, is there any other easier way?

ivory sonnet
#

I figured it out, just saw this example, you can pass callback to data, but it seems I need to use useEffect to have persistent callback reference

atomic moat
#

You can use useReactFlow if you have wrapped your Flow in ReactFlowProvider

#

useReactFlow provides a setNodes function that you can just use to set the node states

const { setNodes } = useReactFlow()

setNodes((nodes) => nodes.map(node => ...))