创建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

 

posted @ 2024-05-11 15:42  青橙娃娃  阅读(8)  评论(0编辑  收藏  举报