-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating state causes id already exists error #19
Comments
please share |
I have same issue, I think. Graph is in react state: const [graph, setGraph] = useState({
nodes: [
{ id: 1, label: "Node 1" },
{ id: 2, label: "Node 2" },
{ id: 3, label: "Node 3" },
{ id: 4, label: "Node 4" },
{ id: 5, label: "Node 5" },
],
edges: [
{ from: 1, to: 2},
{ from: 1, to: 3 },
{ from: 2, to: 4 },
{ from: 2, to: 5 },
],
}); But when I call: setGraph({
nodes: [...graph.nodes, { id: "6", label: 'Node 6' }],
edges: [...graph.edges],
}); I get the error I guess this is the same error as #8: the add node function is being called twice for some reason, thus producing error |
Same issue here |
Same |
Hitting the same problem here. For some more diagnostic color, I randomly generated a string in |
I have the same problem. I have found that supplying a new key every time you update the data works. I update the graph like this: let [graph, setGraph] = useState({ nodes: [], edges: [], rand: "" });
...
setGraph({
nodes: nodes,
edges: edges,
rand: Math.random().toString(),
}); And I use the <Graph
key={graph.rand}
...
/> Hope this helps until we can find a better solution. |
Am I updating the state right?
Not the exact code but I'm doing something like this.
which gives me the following error
Stacktrace shows:
The text was updated successfully, but these errors were encountered: