need help with using elements array in a custom node handler
See original GitHub issueHi, I have a custom node with a plus button attached to the node. I want the button to add a new node right below the one with the plus.
I’m creating the handler in the same way as in your example, Custom node example
This issue is that, for me to add a Node, I have to pass the addNode helper an array of the elements state, but because of the way the handler is passed, elements is always equal to [] (because of closures, the function is passed only when it goes through the useEffect, and thus captures it’s surrounding scope at that time).
Do you have any idea about how to use the elements array state in a custom node handler ? Thank you for your help
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Node.js Tutorial - Node.js Arrays - Java2s.com
To create arrays, you can either use traditional notation or array ... We can specify the index of the element where you want...
Read more >Array - JavaScript - MDN Web Docs
The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name ...
Read more >Array of custom object in Node.js - Stack Overflow
One way or the other you need to iterate. The two ways I can think to do it are: The way you did...
Read more >5. Working with Arrays and Loops - JavaScript Cookbook [Book]
An array is an ordered collection of elements. In JavaScript, an array can be created using formal object notation, or it can be...
Read more >Array methods - The Modern JavaScript Tutorial
Arrays do not form a separate language type. They are based on objects. So typeof does not help to distinguish a plain object...
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

Thank you so much, I’ve been coding with hooks for > 1 year, and I didn’t event know you could pass a function to the set state method… Thank you for your reactivity and for your help
You can pass a function to
setElementslike we are doing it in our custom node example. The first parameter is the currentelementsvalue. Then you could do:Or you could receive the current elements with the way described above and pass it to the
handleAddChildfunction: