dai-shi / react-tracked

State usage tracking with Proxies. Optimize re-renders for useState/useReducer, React Redux, Zustand and others.
https://react-tracked.js.org
MIT License
2.73k stars 72 forks source link

In the useReducer formula, is initialState fundamental #162

Closed BenDmg closed 7 months ago

BenDmg commented 2 years ago

Hi, we use react-tracked effectively for a while, but our state grew after a while and for some reason the entire state re-renders again like if it was useContext, was wondering if it might be because our initial state object with empty values is not an exact 1 to 1 match anymore, as we add stuff we did not keep initializing everything. Trying to get back to what this great piece of code use to give us, thanks !!

dai-shi commented 2 years ago

It doesn't need to be one to one match. It optimizes after property access. So, extra re-render should just happen once. You can try to reproduce something small to check the behavior.

BenDmg commented 2 years ago

yeah its a huge app, won't be able to share here, but will try within that app a smaller provider, it did used to work and that's what's frustrating. Trying to figure out why it's not anymore, is it nested objects ? - don't think so... Any tricks to localize the issue.

Btw huge thanks for your work, not only on this package, and your availability. You're the man !

dai-shi commented 2 years ago

it did used to work and that's what's frustrating.

If you know which version causes your issue, we can check the CHANGELOG.

dai-shi commented 7 months ago

Closing as stale.