Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Creating the Redux Store | Redux in Practice
Introduction to Redux

book
Creating the Redux Store

In the previous chapter, we deleted some files to create an empty structure we can use to build our application. In this chapter, we will build on top of that empty template.

We deleted a file called store.js, which contained the code for creating the Redux store. We will create our own Redux store based on the requirements of our application.

We will set up a Redux Store for a simple Todo application. For reference, this was the code from the store.js, which we deleted:

js
import { configureStore } from '@reduxjs/toolkit';
import counterReducer from '../features/counter/counterSlice';
export const store = configureStore({
reducer: {
counter: counterReducer,
},
});

A Redux Store is created using the configureStore function, which is imported from the Redux Toolkit:

js
import { configureStore } from '@reduxjs/toolkit';

To recap, a reducer is a function responsible for handling a dispatched action and modifying the state based on that. A Redux store needs one or more reducers since reducers are the main method of modifying the application state based on an event.

In the above code, after importing a reducer from the counterSlice as counterReducer, we assigned it to the key counter inside the reducer object.

js
reducer: {
counter: counterReducer,
}

Each feature in a Redux application might have a reducer for handling events. We can pass more reducers into the store by adding more keys to the reducer object:

js
export const store = configureStore({
reducer: {
counter: counterReducer,
clock: clockReducer
},
});
question mark

Select the correct option for creating a Redux store using the todosReducer and name it todos.

import { configureStore } from '@reduxjs/toolkit';
import todosReducer from '../todosSlice';

export const store = ___

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 3

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt