Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Hooks Vs React-redux

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.

like image 297
Ahmad Khani Avatar asked Jun 26 '19 09:06

Ahmad Khani


People also ask

Which is better React hooks or Redux?

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.

Should I use Redux with React hooks?

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.

Is it better to use hooks in React?

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.


1 Answers

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.

like image 165
akshay kishore Avatar answered Sep 30 '22 16:09

akshay kishore