DEV Community

Discussion on: Optimise rendering of children tree subscribed to Context API

Collapse
 
medelba profile image
MedElba

Awesome post! Really very helpful!
I have my context provider wrapping a tab navigator, so every time i switch tab, the context sees the children changing and rerenders, causing all the screen to rerender!
Now I've adopted your solution simply by adding useMemo in the return function of the context and giving as input the state of the context, since it's the only value that context handles! It's working for now ahahah but I only tried for a few hours.. What you think about this approach? Do you think that even with this kind of optimization another state manager like Redux is far better?

Collapse
 
calebdeji profile image
calebdeji

I think it is good. Redux too is okay, but you need to be careful with what you extract from useSelector hook in order to prevent redundant rendering.