redux-toolkit使用

安装 npm i @reduxjs/toolkit

创建store

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { configureStore } from '@reduxjs/toolkit'
import CounterReducer from './counter.slice'


export const store = configureStore({
reducer: {
counter: CounterReducer
},
})

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch
阅读更多