Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials React Redux Basics
React Intermediate FREE

Redux Basics

Lesson 2 of 17 Intermediate Interactive

Redux is a predictable state container for JavaScript apps.

Syntax

REACT
const counterSlice = createSlice({
    name: "counter",
    initialState: { value: 0 },
    reducers: {
        increment: state => { state.value += 1; },
        decrement: state => { state.value -= 1; }
    }
});
Redux Store and Slices
REACT
import { configureStore, createSlice } from "@reduxjs/toolkit";

const counterSlice = createSlice({
    name: "counter",
    initialState: { value: 0 },
    reducers: {
        increment: (state) => { state.value += 1; },
        decrement: (state) => { state.value -= 1; },
    },
});

export const { increment, decrement } = counterSlice.actions;

const store = configureStore({
    reducer: { counter: counterSlice.reducer },
});

console.log(store.getState());