Redux-toolkit: Store does not have a valid reducer .确保传递给 combineReducers 的参数是一个值为 reducers 的对象

Redux-toolkit: Store does not have a valid reducer . Make sure the argument passed to combineReducers is an object whose values are reducers

我不知道为什么显示错误 我什至还没有开始编码 我刚刚编写了文档

给出的 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 的参数是一个值为 reducer 的对象。

您还没有在您的应用中定义任何 reducer 函数

import { configureStore,createSlie } 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 对象

NOTE: combineReducer is also available as an import from @reduxjs/toolkit