CodeBlanks Logo Icon CodeBlanks

What is Redux?

Learn the Redux state management framework.

What is Redux?

Redux is a state management framework that keeps all of the app's state in a single object (the store). It centralizes shared data between components and reduces prop drilling. It has three core parts: store (state), action (change request) and reducer (pure function that applies the change).

The flow is one-directional: a component calls dispatch(action), the reducer returns the new state based on the action, the store updates, and the component reads the new state. This flow makes things predictable and debugging easier. Redux is common in large React Native apps.

Action and reducer

An action is an object describing what to do: { type: 'counter/increment' }. type is required; it may also carry a payload. A reducer takes the current state and an action and returns a new state. Important: the reducer must be pure; the same input always gives the same output and there are no side effects.

Example reducer: function counter(state = 0, action) { if (action.type === 'counter/increment') return state + 1; return state; }. State is never mutated directly; a new object is always returned. This rule is the basis of Redux's predictability.

Practice Write the action object

Define incrementAction. It should be { type: 'counter/increment' }. Export it with export const.

Starter code

App.js
// export the counter/increment action

Sample solution

App.js
export const incrementAction = { type: 'counter/increment' };

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where is state kept in Redux?

  • In a single store Correct answer
  • Inside each component
  • Only in AsyncStorage
  • Only in the file system

Explanation: Redux keeps all state in a single store.

2 Write the action type

Question
{ type: '____/increment' }
Answer
{ type: 'counter/increment' }

Explanation: counter is the slice name.

3 Match each part to its role

Term Meaning
store Holds the state
action Change request
reducer Returns new state
dispatch Sends the action

All lessons in Advanced