5 ms·
React Redux actually uses the Context API (Update: Old context api). "Context is what powers React Redux under the hood. The new context API isn’t to “replace
by jefflombardjr 8y ago
React Redux actually uses the Context API (Update: Old context api).
"Context is what powers React Redux under the hood. The new context API isn’t to “replace Redux”, it just fixes a broken feature that needs to be provided by React. Whether you use it directly or through another API like RR is up to you" [0]
At the end of the linked article the author states "Today, when Redux is more than you need, you can reach for Context." I'd actually argue the opposite. Redux, specifically React-Redux, is an abstraction. An abstraction that simplifies using the Context API. All I need to think about when using Redux is Flux architecture. There is excellent documentation around Redux, context api not as much.
If you don't feel confident about Redux, or would like to get a better understanding of it, check out these three things (in order):
1. Understand Flux Architecture: https://facebook.github.io/flux/docs/in-depth-overview.html#content https://facebook.github.io/flux/docs/in-depth-overview.html#...
2. Understand Redux: https://egghead.io/courses/getting-started-with-redux https://egghead.io/courses/getting-started-with-redux
3. Implement Redux: Read the documentation at https://redux.js.org/ https://redux.js.org/. At this point you should have a good grasp on the concepts so pay attention to implementation details here like designing the state.
[0]:https://twitter.com/dan_abramov/status/964946781493780480?lang=en https://twitter.com/dan_abramov/status/964946781493780480?la...
- timdorr 8y agoWe use the legacy Context API: https://github.com/reduxjs/react-redux/blob/47facdbcae2412d37d72fa5c37cb4e0cd64a9b4a/src/components/connectAdvanced.js#L139-L146 https://github.com/reduxjs/react-redux/blob/47facdbcae2412d3... This article is looking at the new Context API, which uses React.createContext() to create a Provider/Consumer pair of plain components. This has a number of differences in behavior, most critically around blocking updates incorrectly. We are looking to switch to the newer API in 6.0. We have two in-progress PRs for this: https://github.com/reduxjs/react-redux/pull/1000 https://github.com/reduxjs/react-redux/pull/1000 https://github.com/reduxjs/react-redux/pull/995 https://github.com/reduxjs/react-redux/pull/995
- jefflombardjr 8y agoVery cool, thanks for the clarification. To me, this is yet another perk of using RR on top of the actual api. As someone who works on a smaller team, updating our projects to use the new context api would be a significant undertaking. By using RR, the implementation details are left better equipped engineers, our team can focus on meeting business requirements.
- acemarke 8y agoYep, and that was always the advice from the React team. "Don't use legacy context directly in your apps. Libraries may need to use it. If you _need_ to use it, wrap it up in a HOC or something so that you can update it in one place later."
- underwater 8y agoRedux isn’t a simplification of React context; it’s solving a different problem. Context is the mechanism by which state is passed through to components. Redux solves management and lifecycle of that state as well.
- deleted 8y ago[deleted]
- woah 8y agoThere’s a bunch of useless event boilerplate in redux. Worse, it seems to have been conceived without any thought for asynchronous operations (like making requests) and this leads to bizarre patterns like redux-thunk, and even the monstrous redux-saga. I made my own state management framework with context, but it’s basically a less polished version of unstated if you want to check that out. Much saner. Much less cruft.