Skip to content
BENIBIX Learn

Redux

Development🌐 Web DevelopmentFrameworks

Also known as Redux Toolkit, Redux JS, RTK

A JavaScript tool that keeps an app's shared data in one store. It changes by actions.

Think of it like

It is like a bank. You never change the money yourself. You hand in a slip, and the bank does it.

Example

Jack's app has a bug where the cart empties. Redux's tools show every action in order, so he finds the one that did it.

Why it matters

Big apps with lots of shared data stay easy to follow. Every change is written down as an action.

Definition

Redux is a free JavaScript library for keeping an app's shared state in one store. Parts of the app never change the store directly. They send an action, a small note that says what happened. A function called a reducer reads the action and makes the new state. Because every change goes through one path, it is easy to follow. Redux Toolkit is the official way to write it today.

Example code

javascript
dispatch({ type: "cart/addItem", payload: { id: 7 } });
Parts of the app send an action like this. The reducer then makes the new state.
Redux is one such store. A part sends an action, and the store sends back new state.

Common mistake

Adding Redux to a small app that does not need it. Plain component state is often enough.

Key takeaways

  1. 1
    One store. All shared state in one place.
  2. 2
    Actions only. Changes come as small notes.
  3. 3
    Reducers decide. A function makes the new state.