useReactFlow: `setNodes([])` does nothing
See original GitHub issueDescribe the Bug
Calling setNodes([])
in an effect or event callback does nothing. It’s only the setNodes
from useReactFlow
. The setNodes
from useNodesState()
works.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
As described above. This will happen in any application.
Expected behavior
setNodes([])
should remove all nodes.
Screenshots or Videos
No response
Platform
- OS: Win10
- Browser: na. Electron
- Version: "10.0.8
Additional context
This is the implementation for setNodes
. In my debugging, hasDefaultNodes
was false
and onNodesChange
was a function, so we take the else if
branch.
const changes = nextNodes.map((node) => ({ item: node, type: 'reset' } as NodeResetChange<NodeData>));
onNodesChange(changes);
Since my nextNodes
is empty, changes
will also be empty. Hence, applyChanges
find no c.type === 'reset'
change.
setEdges
has the same bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Troubleshooting Guide - React Flow
This guide contains warnings and errors that can occur when using React Flow. We are also adding common questions and pitfalls that we...
Read more >Restore doesn't work well · Issue #2032 · wbkd/react-flow
toObject() => without the positionAbsoute Node's attributes) and the resize/fitView works again and the edges are good as well.
Read more >Layouting bug in react-flow-renderer v10 - Stack Overflow
I just migrated to react-flow-renderer version 10 about 5 hours back (it launched around 10 hours ago). I am trying to arrange nodes...
Read more >beginners 2021-05-13 - Slack Archive
Hi, recently I am trying to use [react-flow](https://github.com/wbkd/react-flow) in my project and I am really new to cljs .
Read more >react-flow-renderer - npm
The example app serves the content of the example folder and watches changes inside the src folder. The examples are using the source...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be nice if
useReactFlow
could continue to work for both. It’s simply very convenient to have access to all nodes and edges (and their setters) without having to do the context work/props passing yourself.We currently work around this bug by passing the
setNodes
andsetEdges
function around using a context.Thank you, @moklick!