jakezatecky / react-checkbox-tree

A simple and elegant checkbox tree for React.

Home Page:https://jakezatecky.github.io/react-checkbox-tree/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Giving complex nodes for checkboxtree getting error

rruichava opened this issue · 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.

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.

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