question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useReactFlow: `setNodes([])` does nothing

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
RunDevelopmentcommented, May 18, 2022

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 and setEdges function around using a context.

1reaction
RunDevelopmentcommented, May 18, 2022

Thank you, @moklick!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found