程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Redux-toolkit: Store 没有有效的 reducer 。确保传递给 combineReducers 的参数是一个对象,其值为 reducers大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Redux-toolkit: Store 没有有效的 reducer 。确保传递给 combineReducers 的参数是一个对象,其值为 reducers?

开发过程中遇到Redux-toolkit: Store 没有有效的 reducer 。确保传递给 combineReducers 的参数是一个对象,其值为 reducers的问题如何解决?下面主要结合日常开发的经验,给出你关于Redux-toolkit: Store 没有有效的 reducer 。确保传递给 combineReducers 的参数是一个对象,其值为 reducers的解决方法建议,希望对你解决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

大佬总结

以上是大佬教程为你收集整理的Redux-toolkit: Store 没有有效的 reducer 。确保传递给 combineReducers 的参数是一个对象,其值为 reducers全部内容,希望文章能够帮你解决Redux-toolkit: Store 没有有效的 reducer 。确保传递给 combineReducers 的参数是一个对象,其值为 reducers所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。