Redux Core Concepts Made Easy

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human
Search for a command to run...

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human
Amazing! I don't know why I didn't notice this until now. Definitely one of the best Redux tutorials for beginners. ✨
Thank you for this article it was really helpful. But what if i have a full stack app which is quite large. I have an app that is setup for docker. And i want to add redux to it. There is already React Router setup. What is the way in which I can successfully learn to setup redux as well.
Glad that you liked it.
For your question of using redux in a Full-Stack App where React-Router is already there, I have an app already built doing the same.
https://github.com/atapas/full-stack-reborn/
I am using reactjs, redux and react-router at the front end and got a sails back-end along with postgreSQL as DB. Unfortunately this repo can not be made public now. But, send me your github id, I shall add you as a Collaborator. You will be able to read the code and we can collaborate further there. Let me know if it works for you.
Okay, thank you for your help. this is my ID: sidd-92
Done!
Done!
Redux, the super cool state management tool is easy to learn and awesome to put in practice. How cool it would be when we use it with ReactJs in a meaningful way. Welcome to the series to explore it!
Introduction This is the second post of the series: A blend of Redux and ReactJs - State Management Made Easy! If you are already comfortable with the core concepts of Redux, great! If you are just getting started with Redux, I would like to encoura...
Traditional SSR is great, but it has a massive buffering problem. Let's look into the SSR Streaming and learn how it could be a game changer.

Learn how to build maintainable, reusable forms in React using design patterns like custom hooks, compound components, and context for scalable CRUD

Learn how JavaScript variables work, including let vs const, primitive and reference types, pass by value, and how JavaScript stores data in memory.

A beginner-friendly introduction to JavaScript covering what it is, how it works, and how to set up your JavaScript environment

Learn how the promises are handled internally using event loop. This concept is essentials to debug and work with async programming.

GreenRoots Blog - A Blog by Tapas Adhikary
186 posts
Educator | YouTuber | Building ReactPlay | Let's Connect
This post is the first in a series of three posts to explain the core concepts of Redux, how does it work well with React? and Some cool hooks to make the understanding easier and better. We will be building a small app alongside to realize these concepts better.
I have noticed that, there are good amount of myths around Redux. See if any of these are familiar to you.
We will break these Myths as we go ahead with this post and the subsequent ones in the series.
Redux is a client side State Management library. But wait, What is State and why do I need to manage it?
A state can be defined as, the outcome of an action performed by user. A state should be described by a data structure so that, state can be understood structurally.
Say, you got a button on a webpage. When click on the button, a network call has been made. Once the call completes successfully, page is loaded with user information and a success message. In this scenario, the state is the user data and the success message like this:
{
'name': 'bob',
'age': 32,
'job': 'blogging'
}
{
'message': 'The user information has been
updated successfully!'
}
Over the period of time, if the user data gets modified due to some other interaction(like, edit button click), the state changes and hence the data as well.
Without a state management system, it is difficult to know what the state of our application is? We can look at the DOM. We can check DOM elements but please take a note that, State is not as same as DOM. State deals with the actual data representation out of the action been performed and the data is the Source of the Truth.
A State management tool like Redux helps us in creating these data structures and updating them when a new action occurs.
Let us take an example of a Reactjs app(it can be an Angular or Vue app too) called Jokking. After Login into this app, user sees the list of Jokes, a random Joke, a single selected Joke. User of the app can also search any Jokes and can like them by hitting a button!
As you would have realized by now, we are already dealing with few sets of data.
true or false to indicate if user in a logged-in session.The diagram below shows how these data can flow unidirectional way from one component to another as top-down. As you see, the jokes data needs to flow from App component to 'Jokes' component and downstream. Not only that, Search and Like components also need the jokes data to be operational.
Data Flow within components could be a nightmare when app grows
It could be really challenging and error prone to maintain and manage the state of the data across components in a meaningful-way once the app grows bigger and larger.
Also each of these components might cause change to the initial data state or create multiple clones based on the usage and need. This is where Redux comes into picture.
state is maintained.Redux is an open-source JavaScript library for managing application state in Predictable and Flexible ways. State management with Redux is Centralized and it is easily Debuggable.
With this, let us rework on the data flow a bit for our Jokking app. Imagine, there is a single data store where we can keep all the data and maintain their state. The revised diagram will look like this:
A Common Data Store for the data state
Redux helps in managing the state and we know that, the state gets stored and managed in a Store. Hey but,
Let us start by looking into the following diagram:
State management using Redux
Now, let us understand each of these components one by one.

Actions are the desire of doing something. Please note, actions are more descriptive way of telling what to perform than actually performing it. Actions are responsible for sending data to the store with the help of dispatch and reducers.
In redux, Actions are simple JavaScript functions that returns an object. This object describes the name of the action with a mandatory type property and optionally any input needed to perform the action. An Increment action can be defined as,
const increment = () => {
return {
type: 'INCREMENT'
}
}

Reducers specify how the application's state changes in response to actions sent to the store. Remember that actions only describe what happened, but don't describe how the application's state changes, Reducers does it.
Reducer is a JavaScript function that changes the state based on the Action dispatched to the Store. A reducer for the Increment action:
const counter = (state = 0, action) => {
switch(action.type) {
case 'INCREMENT':
return state + 1;
default:
return state;
}
}

A store holds the whole state tree of your application. The only way to change the state inside the store is to dispatch an action on it. There is no direct setters available.
A Store can be created as,
import { createStore } from 'redux';
const store = createStore(counter);
// Note: we passed the reducer to create the store.
Once the store creation is done, we can setup the dispatch of Action on it,
store.dispatch(increment());
That's it, you can always subscribe to the store to get what is the current state of your data,
store.subscribe(() => {
console.log(store.getState());
});
Once you see the entire sequence together, it would look like:
import { createStore } from 'redux';
//Action
const increment = () => {
return {
type: 'INCREMENT'
}
}
//Reducer
const counter = (state = 0, action) => {
switch(action.type) {
case 'INCREMENT':
return state + 1;
default:
return state;
}
}
//Store
const store = createStore(counter);
store.subscribe(() => {
console.log(store.getState());
});
//Dispatch
store.dispatch(increment());
The example here(Increment a counter) could be a very small one to recognize the power of State Management. When the application grows, data becomes difficult to manage between states, Redux kind of tools are very handy in those cases.
In future posts, we will see how Reactjs and Redux can come together to manage state for a Web Application. We will also see the downside of Redux and when we can avoid it.
Hope the post was a good start for understanding the core concepts of Redux without much difficulties and couple of myths are broken already!