我不知道为什么它显示错误我甚至还没有开始编码我刚刚写了一个文档中给出的configureStore语法
我通过提供商上传到index.js文件
这是我的应用程序.js
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<h1>Redux Tool Kit</h1>
</div>
);
}
export default App;
这是我的商店,js
import { configureStore } from '@reduxjs/toolkit'
const store = configureStore({
reducer: {},
})
export default store;
这是我的index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import {Provider} from 'react-redux'
import store from './store/store'
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode >
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
结果是错误存储没有有效的缩减器。请确保传递给combineReducers的参数是一个其值为reducers的对象。
您尚未在应用中定义任何reducer函数
import { configureStore,createSlice } from '@reduxjs/toolkit';
const reducerSlice = createSlice({
name: 'store',
initialState: {},
reducers: {
someAction: function() {
}
}
})
const store = configureStore({
reducer: {
someReducer: reducerSlice.reducer,
}
})
export default store;
您还可以在应用程序中创建多个slices/reducers
,并使用combineReducers
将其传递给configureStore 中的reducer对象
注意:
combineReducer
也可以作为从@reduxjs/toolkit