You can use a separate state management library, outside your component, and trigger actions from inside the node directly.
This technic is mentioned in the official doc Using a State Management Library
.
There it says the following:
As you might have seen in the previous guides and examples, React Flow can easily be used with a local state for handling the nodes and edges of your diagram. When your app grows and you want to alter your state from within your nodes for examples, things can easily get more complex. To avoid passing down functions through the node data field, you could use a React context or add a state management library as explained in this guide.
If for example, you make a Zustand store as shown in the doc, and expose a deleteNode
action from it, then, you can access it from your custom node with const deleteNode = useStore((s) => s.deleteNode);
.