naisutech / react-tree

Hierarchical tree component for React in Typescript
https://naisutech.github.io/react-tree/
MIT License
206 stars 25 forks source link

callbacks causing rendering problems #68

Closed peeveen closed 2 years ago

peeveen commented 2 years ago

Hi,

The onSelect and onOpenClose callbacks are currently called from within a setState() hook. If I have some code in my callback function to modify my app state (which, in turn, will cause another component to re-render), I get the dreaded "cannot update a component while rendering a different component" error in the console. I've fixed it for now by removing the callbacks, and instead, just having this in the main component body, but there may be a better solution:

image

ortonomy commented 2 years ago

This is for sure a better solution, and I saw your PR. Made a comment

ortonomy commented 2 years ago

I've published v3 which removes all the calls in memos, and take into account your PR, but doesn't use the same approach, closed. @peeveen