5 ms·
Huh. My coworkers have been talking about React's context API as an alternative/replacement for Redux and that the industry is generally "moving away from using
by archarios 8y ago
Huh. My coworkers have been talking about React's context API as an alternative/replacement for Redux and that the industry is generally "moving away from using Redux." Is this at all true/valid? I've been skeptical since I like Redux a lot and haven't been able to understand how Context is a true replacement for Redux given what I have read.
- acemarke 8y agoI wrote a post earlier this year that talks about how things like context, GraphQL, etc, all relate to Redux. It's still relevant: https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet/ https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet... Also, Dave Ceddia wrote a good post comparing Redux and the context API: https://daveceddia.com/context-api-vs-redux/ https://daveceddia.com/context-api-vs-redux/ FWIW, my rough stats indicate that somewhere around half of all React apps use Redux, and Redux is also used with other UI frameworks as well. Redux definitely isn't going away any time soon :)
- oh-kumudo 8y agoVote for Mobx to replace Redux. Having done so, not missed a bit.
- manigandham 8y agoAgreed. State lifecycle is all the same but Mobx automates 2/3rds of the tedious work and is much more natural to use.
- oh-kumudo 8y agoNot to mention that the API is very intuitive and programmer friendly. For me, using Mobx doesn't force me to write things its own way, but instead enables me to write things MY way, but just hook it up with Mobx when needed. It is a more of a library than a framework, a guest not a intruder. While with Redux, not that I am bitching about it, it first states that I need to accept several principles before I can better appreciate it. Then here comes all the middlewares, like redux-saga/redux-thunk and the list goes on. As a causal, meaning I am not writing js fulltime but do use it in some non-trivial situtation when needed, I feel it quite heavy and burdensome, making hesitant to adopt it unless being asked to.
- quantummkv 8y ago> I've been skeptical since I like Redux a lot and haven't been able to understand how Context is a true replacement for Redux given what I have read. That is because context was never intended as a replacement for Redux or any other state management library. In fact Redux itself uses context under the hood. Context is more of a low level api. Somewhat similar to TCP/IP. You never work with TCP/IP directly but use high level abstractions like HTTP that work on top of TCP/IP and provide a simple interface.
- 11235813213455 8y agokind of, yes: https://codesandbox.io/s/jznpj65nm5 https://codesandbox.io/s/jznpj65nm5
- tracker1 8y agoYou can effectively maintain your own component independent state via context and the context API. Where Redux shines is in predictable state management. Or more predictable depending on how you manage async requests to an external resource. Personally, I find for mid-large apps that Redux is usually a better approach. For small-mid, you're likely better off using the new context directly. Also don't forget you can maintain in-component state.
- beaconstudios 8y agoonce hooks are in, I think React Context will be a lot more usable. Right now, its composability isn't great because you have to use nested render props because it's not very HoC friendly. React Context makes a lot of sense though, because you'll effectively be able to create your own Redux nested at any level in the DOM. This means local state will be much easier to manage and you won't have the issue of having to stuff all your disparate contextual data into one shared store.