React Hooks vs Redux for application state management

1. Redux

What is redux?

  • You have large amounts of application state that are needed in many places in the app
  • The app state is updated frequently
  • The logic to update that state may be complex
  • The app has a medium or large-sized codebase, and might be worked on by many people
  • You need to see how that state is being updated over time”
npx create-react-app my-app — template redux

2. Hooks

Similar functionality to Redux can be achieved through React Component Hooks. More specifically the useContext and useReducer hooks.

3. Comparisons

The above two apps created are extremely simple and give an idea of how both Hooks and Redux are implemented. In a real-world complex application, the process of using both will certainly be more complex.

  • Redux creates one large global state container whereas useReducer is used to create a more localized shared state.
  • Redux is a third-party library whereas React Hooks come out of the box with React
  • useContext hook gives a Provider which wraps around child components to create a shared state whereas Redux provides useSelector hook to get the state object of interest and actions to manipulate the state.
  • Redux dev tools allows one to time travel through the application state to see what modifications were made to the state.

Tl:Dr; Summary

So all in all, Redux and React hooks should be regarded as tools in your arsenal to be used together and not something that you need to pick between. For smaller projects, the clear winner are React Hooks for ease of use whereas for more more larger, complex applications Redux and Hooks can be used in conjunction. Redux should be preferred to set up global state for applications while React Hooks should be used for managing the local state within components.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store