Yomguithereal/baobab-react

UseRoot Causes double re-render

vinceprofeta opened this issue · 4 comments

When using useRoot my App.js component renders twice on refresh. Using the higher order root resolves the issue.

Hello @vinceprofeta. Would you be able to open a PR to solve this issue?

Any update on this?

No. Can you provide a minimal reproducible example so I can investigate?

The issue seems to be centered around this effect. It causes the component tree to render when it sets the tree state inside of the effect. You essentially set state twice . https://github.com/Yomguithereal/baobab-react/blob/master/src/hooks.js#L31

I’m not entirely sure it’s needed using the tree as a singleton. My workaround was to just use a higher-order component for the root like Vince said above.