reactjs - Redux-toolkit:Store 没有有效的 reducer。确保传递给 combineReducers 的参数是一个其值为 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 的参数是一个其值为 reducers 的对象。
解决方案
你还没有在你的应用程序中定义任何 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 对象
注意:
combineReducer
也可作为从@reduxjs/toolkit
推荐阅读
- python - 如何为每个 ID 的特定变量创建滞后变量
- python - 如何在python中绘制两个比例非常不同的系列
- javascript - 除了 HTMLAnchorElement 之外,这个 html 元素的类型是什么
- c++ - mongocxx 驱动程序中的分段错误
- c# - C# 中等效的 GRG 非线性求解器
- javascript - 如何为网络图自定义颜色?
- sql - 列出系列中两个表之间的不同变体
- java - 每当我先输入更大的数字时,它都不会打印出任何东西
- c# - 在 C# 中,使用脚本将命令添加到 PowerShell InitialSessionState 并使其可从 C# 中发现
- python - 为什么这个结果比等效函数的另一个结果更准确