dgreene1 / react-accessible-treeview

A react component that implements the treeview pattern as described by the WAI-ARIA Authoring Practices.
https://dgreene1.github.io/react-accessible-treeview
MIT License
277 stars 37 forks source link

The `flattenTree` utility is mutative #22

Closed jossmac closed 1 year ago

jossmac commented 3 years ago

Not expecting a fix, just a heads up for folks who encounter the same issue.

You may see something like:

TypeError: Cannot create property 'id' on number '2'

🚨 Be wary of shallow cloning, objects are copied by reference:

flattenTree({ name: '', children: [...data] }) // `children` arrays (and other objects) are still mutated!

✅ Consider something like lodash.cloneDeep:

flattenTree({ name: '', children: cloneDeep(data) }) // original `data` remains intact
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue was closed automatically since it was marked as stale because it has not had recent activity. Thank you for your contributions.