React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
When I selected a node, the node becomes selected and immediately unselected according to my logs. I know that this is because caused calling setSelected(id). When I remove that call, the node just stays selected after I click it. I don't see why this shouldn't work as it's not so different from the example here where selected nodes are kept track of: https://reactflow.dev/api-reference/hooks/use-on-selection-change. The parent component needs to know which node is selected in the child component.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
Create two components, a child and a parent
Put the react flow component in the child
Return the child component in the parent
Wrap the parent with ReactFlowProvider
Create some state in the parent `const [selected, setSelected] = useState<string | null>(null);
Use useOnSelectionChange to call setSelected(id) when a node is selected
Observe that the node gets selected and then immediately unselected
Expected behavior
I expected the node to get selected and to be able to track the id of which node is selected using useState but instead the node gets unselected when I call the state setter setSelected
Describe the Bug
I have two components, Parent(Parent.tsx) and Child(Child.tsx). The Child component actually has the ReactFlow component:
The Parent contains the Child but also needs to be aware of what node is selected in the Child:
In App.tsx, parent is wrapped like this:
When I selected a node, the node becomes selected and immediately unselected according to my logs. I know that this is because caused calling
setSelected(id)
. When I remove that call, the node just stays selected after I click it. I don't see why this shouldn't work as it's not so different from the example here where selected nodes are kept track of: https://reactflow.dev/api-reference/hooks/use-on-selection-change. The parent component needs to know which node is selected in the child component.Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
ReactFlowProvider
useOnSelectionChange
to callsetSelected(id)
when a node is selectedExpected behavior
I expected the node to get selected and to be able to track the id of which node is selected using useState but instead the node gets unselected when I call the state setter
setSelected
Screenshots or Videos
No response
Platform
Additional context
No response