Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Combining Reducers Cleanly | Scaling Redux in Larger Applications
Tilstandshåndtering med Redux Toolkit i React

bookCombining Reducers Cleanly

Sveip for å vise menyen

When you have multiple slices, you need to combine them in the store. Redux Toolkit makes this simple.

Combining Slices

You pass all slice reducers into configureStore:

import { configureStore } from '@reduxjs/toolkit';
import userReducer from '../features/user/userSlice';
import tasksReducer from '../features/tasks/tasksSlice';

export const store = configureStore({
  reducer: {
    user: userReducer,
    tasks: tasksReducer
  }
});

Each slice becomes a key in the global state.

You can access them like this:

  • state.user;
  • state.tasks.

This keeps your state structured and predictable. Each part of the app has a clear place in the store.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 6. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 6. Kapittel 3
some-alt