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

Giving complex nodes for checkboxtree getting error

Open rruichava opened this issue 4 years ago • 2 comments

Hi @jakezatecky, When I defined the nodes and gave to checkbox tree it's getting map of undefined, Can you please take a look below codesanbbox url. Can you please tell me why it's getting error.

rruichava avatar Apr 26 '21 07:04 rruichava

The error being returned is very obscure, but it occurs due to the fact that you have some values that are integers (e.g., 1) and some values that are string representations of those integers (e.g., "1"). This is causing an issue where two nodes are resolving to the same values and thus violating the uniqueness requirement for this component.

Unfortunately, in JavaScript objects, integers keys are really string keys, which causes issues with the internal implementations of this tree component. One of the ways this component optimizes performance is by destructuring the source tree into a flat object that maps each node value to its other attributes. When you have two nodes, one with value 1 and one with value "1", they overwrite each other in this mapping object, thus causing the errors you are seeing.

jakezatecky avatar Jun 08 '21 22:06 jakezatecky

The new v1.7 release, pushed today, also provides this more helpful error. See the updated Code Sandbox example:

https://codesandbox.io/s/react-checkbox-tree-example-forked-56ngc?file=/src/components/Widget.js

jakezatecky avatar Jun 08 '21 22:06 jakezatecky