Ask Your Question
1

What is the configuration for Redux Toolkit?

asked 2021-09-24 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-11-04 11:00:00 +0000

nofretete gravatar image

The configuration for Redux Toolkit is minimal as it provides a set of default values and conventions for setting up a Redux store. The basic configuration for creating a Redux store using Redux Toolkit involves importing the necessary modules and creating a store using the toolkit's createSlice and configureStore functions. Here is an example of a basic configuration:

import { createSlice, configureStore } from '@reduxjs/toolkit';

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

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

export default store;

In this example, we first create a slice using the createSlice function and define its name, initial state, and reducers. We then create a store using the configureStore function and pass in our reducer, which is generated from our slice using the counterSlice.reducer property. Finally, we export the store so that it can be imported and used in other parts of the application.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-24 11:00:00 +0000

Seen: 8 times

Last updated: Nov 04 '21