Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast changing states without Redux

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

like image 406
0xChqrles Avatar asked Apr 12 '21 08:04

0xChqrles


1 Answers

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.

like image 136
Dennis Vash Avatar answered Oct 17 '22 13:10

Dennis Vash