react-checkbox-tree icon indicating copy to clipboard operation
react-checkbox-tree copied to clipboard

How to add custom key: value pairs to TreeNode

Open Jack-Tilley opened this issue 5 years ago • 1 comments

Hello,

I am using react-checkbox-tree in a project and I am trying to add custom key: value pairs to some TreeNodes. (ie:)

let myCustomNode = {
                value: "normalValue",
                label: "normalLabel,
                newCustomKey: "myCustomKeysValue"
        }
setNodes(myCustomNode)

...

return(
    <CheckBoxTree
    ...
    nodes={nodes}
    >
)

However, when I try to access the newCustomKey value with a console.log(referenceToMyCustomNode), I can see that the default values of value and label are there, as well as the other default values children etc. (attempting to access referenceToMyCustomNode.newCustomKey will always result in undefined)

I am wondering if you could help me understand why I am not able to see the new custom key: value pair.

Side note: When I check the parent node's key:value pairs and select children, I am then able to see all the custom key: value pairs the original node has been given. This means that key: value pair is attached to the TreeNode but we cannot access it directly for some reason.

Any help would be greatly appreciated.

Jack-Tilley avatar Nov 04 '20 18:11 Jack-Tilley

I assume you are accessing these nodes from the onChange event, right?

There is definite value in being able to set arbitrary key/value pairs for a given node and having them propagate to the handlers. This should be a straightforward implementation for this library.

jakezatecky avatar Nov 05 '20 11:11 jakezatecky