创建reacte工程2
1 配置store
1)安装 npm install @reduxjs/toolkit react-redux
【index.js】
import {Provider} from 'react-redux'
import {store} from 'store'
<Provider store={store}><App/></Provider>
【store/index.js】
import {configureStore} from '@reduxjs/toolkit'
import homeReducer from 'modules/home.js'
const store=configureStore({
reducer:{
home:homeReducer}
})
export default store
【modules/home.js】
import {createSlice} from '@reduxjs/toolkit'
const homeSlice=createSlice({
name:'home',
initialState:{},
reducers:{},
})
export default homeSlice.reducer