Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
bagfox8724yIt’s not hard to use a global state with global events without using redux and all of it’s annoying bits and peaces. No need to pass things around, use HOC‘s.
-
Voxera113974yLearn hooks and for the case of disconnected state, useContext.
Its specifically designed to solve that problem of having a state high up without having to pass it through every component on the way.
And no, its not wrong to manage state that way if it works.
If you start having real problem you might look into some state management libraries but useContext and the other state related hooks can handle quite complex applications out of the box, which means less modules to keep updated. -
Generally speaking its totally ok to lift state up and etc. I generally decide where a state will "live" and then kinda make the call from there.
As others said context works to spread it around without a lot of excessive prop drilling from way u high down low, but prop drilling isn't a problem all by itself either.
If you're doing fine I'd avoid jumping to redux at this point. Redux is it's own kinda bear and if you're in good shape I'd be hesitant to reach for something like that. -
Voxera113974y@N00bPancakes I agree that you should avoid redux if you do not need it.
Generally speaking, all such state frameworks adds overhead and if your unsure if you need them you probably don’t.
And as you say, prop drill down is perfectly fine in many cases, especially between parts within a component since its less complex, a bit more code but also easier to follow.
Context is most useful when you need to either share state between otherwise unrelated components in different parts of the tree, or reusing a component within multiple other components that by them self have nothing to do with this shared state.
Context like most state management introduces a discontinuation of state trail making it more difficult for others to follow how information travels.
Use it when you know its the right way to avoid hard coupling of unrelated components and avoid it within a set of related components if you can.
Clear, readable , easy to follow code is going to be much easier to support over time :)
Related Rants
Is it fine to manage React states on your own ( kinda lifting up the state way ) in a medium size application? I've built 70% of the application without a lot of trouble. The only problem is there's no way to pass states to the sibling components without lifting up the state and lifting up the states decreases the modularity of the code. A lot of functions (handlers) have to be re-written in different components.
Would I be better off using Redux, etc. Thoughts?
rant
react
state management
question