安装依赖
需要安装3个
npm install @reduxjs/toolkit
npm install redux
npm install react-redux
定义一个store
在src文件夹新建文件夹store,在store文件夹下新建文件index.js:
import {
createSlice, configureStore } from '@reduxjs/toolkit'
const counterSlice = createSlice({
name: 'counter',
initialState: {
count: 0,
},
reducers: {
increment: (state) => {
state.count += 1
},
decrement: (state) => {
state.count -= 1
},
incrementByAmount: (state