Yomguithereal / baobab-react

React integration for Baobab.
MIT License
310 stars 38 forks source link

UseRoot Causes double re-render #134

Open vinceprofeta opened 4 years ago

vinceprofeta commented 4 years ago

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

Yomguithereal commented 4 years ago

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

vcardins commented 2 years ago

Any update on this?

Yomguithereal commented 2 years ago

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

georgehenderson commented 2 years ago

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.