3 ms·
The newish `useReducer` is basically redux but tied into react like in elm.
by omeid2 3y ago
The newish `useReducer` is basically redux but tied into react like in elm.
- satvikpendem 3y agoI'm assuming you mean `useReducer` with `useContext`, but note that they are not a replacement for Redux: https://blog.isquaredsoftware.com/2021/01/context-redux-differences/ https://blog.isquaredsoftware.com/2021/01/context-redux-diff...
- omeid2 3y agoThat article makes a lot of hand-wavy assertion and makes up strange definitions. userReducer, specially with useContext does absolutely replace Redux and provide mechanism for state management. The article is, in short, just wrong.
- satvikpendem 3y agoThe main point is here: https://blog.isquaredsoftware.com/2021/01/context-redux-differences/#context-and-usereducer https://blog.isquaredsoftware.com/2021/01/context-redux-diff... Context updates all components while Redux and similar state management tools, because they live outside of React, do not. That's the main reason to use true state management tools over context. If you have a relatively small application or you don't care about that, continue using context. The article is also by a Redux core maintainer so you might call that biased but they know what they're talking about, since they're privy to React design decisions much more than regular users.
- omeid2 3y ago> Context updates all components. All the components that consume it. Not the whole tree under the provider.
- satvikpendem 3y agoIt is the whole tree, actually. That's one reason I don't use context.
- omeid2 3y agoThat is simply not true. Only via a Consumer or useContext hook do you subscribe to hooks. It is well documented and implemented like so. https://react.dev/reference/react/useContext https://react.dev/reference/react/useContext > useContext is a React Hook that lets you read and *subscribe* to context from your component. Emphasise mine.