After introducing hooks to Reactjs
, Are they a good replacement for global store management like Redux
or not? It's about their performance to react.
I have used Redux
and redux-saga
in my recent projects but after introducing hooks I'm interested to replace them.
Redux and React Hooks should be seen as complements and also as different things. While with the new React Hooks additions, useContext and useReducer, you can manage the global state, in projects with larger complexity you can rely on Redux to help you manage the application data.
tip. We recommend using the React-Redux hooks API as the default approach in your React components. The existing connect API still works and will continue to be supported, but the hooks API is simpler and works better with TypeScript.
Hooks make React so much better because you have simpler code that implements similar functionalities faster and more effectively. You can also implement React state and lifecycle methods without writing classes.
One thing you need to understand is that hooks aren't meant to replace redux stores nor are they used for global store management. You use hooks so as to make the implementation of the components easier(replacing class components with functional components ), the components will themselves still rely on some data that is stored in the redux store. You use redux so that multiple components in your app can use the same redux store.
For example, say you have 2 components a <Hello>
that says "Hello user_name" and a <Welcome>
that says "Welcome user_name". Now both these components require the same data which is user_name. If we use a redux store we can store the data in a single location and use it throughout the app by passing it as a prop. Now we can implement the <Welcome>
and the <Hello>
with hooks instead of class components but the data that they need should come from a global store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With