Right now I’m designing a rather important architecture at work, and I’m using React for it. After writing a simple enough implementation with Redux, I came to the conclusion that, in fact, I don’t need Redux in this architecture, since I’m only storing auth information. Context API seems to be enough.
So, in order to have a mutable and reactive value in the application context, I must choose between useState and useReducer hooks.
While studying the matter, I found a rather good answer to this question:
- When it’s just an independent element of state you’re managing:
useState
; - When one element of your state relies on the value of another element of your state in order to update:
useReducer
.
Although the examples given by the author are way too long, the idea is spot on. In my particular case, since the state is just a monolithic block of data, useState
seems to fit my needs.