array-to-tree
array-to-tree copied to clipboard
Maximum call stack size exceeded
When data had 2 or more top levels 'root' there is stack overflow occured. Here is representation:
https://repl.it/@Nexis/NotableElegantLaws
Just remove top root level and all works fine.
The same issue here
It seems that problem is in "ParentId": 0
Lib considers it as undefined.
The default rootID value is '0'. According to the source code analysis, if the customID and rootID passed in the data are repeated. Then this problem will occur. Therefore, I think a better solution is to customize the rootID configuration to ensure that the rootID is unique.
such as
const tree = arrayToTree(array, { parentProperty: 'ParentId', customID: 'Id', rootID: 'root' });