I'm working on a website with fast changing states and many broadcasts, and I'm trying to create my own global state management with hooks and Context. The only solution I've found to avoid useless rendering is to create two context per state, one for the state updaters methods and one for the state itself. I ended up having dozens of contexts.
It doesn't look like a good design, but I don't have any other ideas and I'm still thinking that it could be possible to create a complex react app without a third party library to handle state management.
Do you have any suggestion? Thanks
Firstly notice, Context API is not a state management tool.
Currently (v17
) there is no bailout for Context consumers.
If you don't know what does it mean, check out this answer
You are right, you need to have multiple Context providers to reduce the useless renders.
As for your other question:
"Could be possible to create a complex react app without a third-party library to handle state management?"
I'm working on a very complicated project on Facebook, and we manage it only with Context API (we have situations of useless renders too, and that's OK), so basically the answer is "Yes".
As a general suggestion before going on the "Context Only" way or any state management solution, you should profile application performance, mostly it's just premature optimization, and having "useless" renders is meaningless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With