Cannot add item: item with id <ID> already exists. Graph not updating.
See original GitHub issueconst [graphData, setGraphData] = useState(g1)
// addNode onClick function for button Change Graph.
const addNode = (e) => {
e.preventDefault()
console.log('addNode clicked!')
setGraphData(g2)
}
return
<div className='graphContainer'>
<Graph
graph={graphData}
options={options}
/>
</div>
graphData is updated with correct data but <Graph> component gives error saying Cannot add item with existing ID but g1 and g2 has nodes with different IDs.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Cannot add item: item with id <ID> already ... - Bountysource
Cannot add item : item with id <ID> already exists. Graph not updating. ... // addNode onClick function for button Change Graph. const...
Read more >Can't create nodes in visjs, ID already exists - Stack Overflow
I set a break point in the code to check the nodes and values and as you can see in the image, the...
Read more >Microsoft Graph copy sharepoint files item not found and other ...
I received the error that the "item was not found" and the I also included the driveid and got the error "item already...
Read more >JSON Item Update API - Support - KaiNexus
NOTE: These Attributes and Fields must already exist on the Item's Template in KaiNexus. PRO TIP: The JSON Item Update API cannot be...
Read more >Participant Import, Update, & Export Messages (EX) - Qualtrics
Failed to update user for new person, username already in use: Unique identifiers were not updated because the new unique IDs from your...
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 Free
Top 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
@chandrarishabh so I had an example where I select a graph number to load with useState and got the same result of where it breaks from
already exists
so I added akey
prop to the Graph like I would for mapping children and for some reason that resolves it for me.basically, react needs a way to identify it as a new child of the whole component so that it doesn’t rerender an older one.
@chandrarishabh I made a codesandbox for it
https://codesandbox.io/s/interesting-spence-onwor?file=/src/App.js
Basically the selectGroup in my case was an id to graph, in this example, I add a new random node and edge to the graph and use a uuid as key.
You’ll see that there are two factors that fix this bug, a deep clone of the graph when reseting or adding a node and the uuid for the key.
I think the issue is that when you manipulate the data as is without deepcloning it, the graph representation of the object tells the Graph that it hasn’t changed and without a key, the wrapper doesn’t know it is a different graph