DEV Community

Cover image for Redux don't need Redux. || Redux in a nutshell.
Swastik Yadav
Swastik Yadav

Posted on • Edited on

4 2

Redux don't need Redux. || Redux in a nutshell.

Redux

A JavaScript state management library.

Which is 90% convention and 10% library.

When different components of the app needs to share information back and forth, things become very messy very quickly.

redux-visual

Philoshopy of Redux is to keep a single source of truth instead of each component managing their own internal state.

And this dramatically simplifies the state managment proccess.

Redux is based on 3 core principles:

Action, Reducer, and State

Remember, when I said Redux is 90% convention. Its these 3 concepts. These concepts are not Redux specific.

Their is a saying that “Redux don’t need Redux”.

To understand what it means, let’s take a look at Actions and Reducers.

Action: Is an object with type & payload as key. Which is dispatched.

Reducer: Is a pure function which returns a new state, based on action’s type and payload. Pure function is the key here.

See, in React there is a hook called useReducer, so with combination of useReducer and useContext, you can achieve the same behaviour as Redux without actually using Redux.

That’s where the saying comes in. (Redux don’t need Redux)

Infact you can implement your own Redux library in just 24 lines of code.

Here is the complete Redux flow.

Redux flow

  • Dispatch an action.
  • Reducer returns a new state based on action type and payload.
  • Redux store is updated and the app is synced via subscribe method.

The 10% which is the actuall library are the helper methods and performance optimization techniques provided by Redux.

So, that was Redux in a nutshell.


So, that is it for this post. If you anyhow liked this post, make sure to show your support.

Will see you in the next post.

I also run a weekly newsletter, so you can join me there also: https://swastikyadav.com

Thank You!

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay