Swastik Yadav

S Y

Navigate back to the homepage

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

Swastik Yadav
April 12th, 2023 · 1 min read

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.

Thank You!

More articles from Swastik Yadav

9 useful code snippets for everyday JavaScript development || Part 2

This is the 2nd post with 4 JS code snippets that you can use in your everyday JavaScript development.

March 10th, 2023 · 1 min read

9 useful code snippets for everyday JavaScript development || Part 1

In this post we will look at some of the most common JavaScript snippets which will help you with your everyday JavaScript development.

February 15th, 2023 · 2 min read

DiaryOfADev, Success stories of underdog developers.

Every week we share an underdog developer's story and a deep dive into a programming concept.

© 2021–2024 Swastik Yadav
Link to $https://github.com/SwastikyadavLink to $https://www.linkedin.com/in/swastikyadav/