gpt4 book ai didi

reactjs - Uncaught Error : Expected the enhancer to be a function

转载 作者:行者123 更新时间:2023-12-05 08:23:31 26 4
gpt4 key购买 nike

I am trying to call the reducer from the component and want to render that in component , but when I am trying to store the reducer in the createStore() method of redux above error is coming. My Code is like this:-

import { applyMiddleware, compose, createStore } from 'redux'
import thunk from 'redux-thunk'
import { browserHistory } from 'react-router'
import makeRootReducer from './reducers'
import { updateLocation } from './location'
import allReducers from './reducers';

export default (initialState = {}) => {
// ======================================================
// Middleware Configuration
// ======================================================
const middleware = [thunk]

// ======================================================
// Store Enhancers
// ======================================================
const enhancers = []

let composeEnhancers = compose

if (__DEV__) {
const composeWithDevToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
if (typeof composeWithDevToolsExtension === 'function') {
composeEnhancers = composeWithDevToolsExtension
}
}

// ======================================================
// Store Instantiation and HMR Setup
// ======================================================
const store = createStore(
allReducers,
makeRootReducer(),
initialState,

composeEnhancers(
applyMiddleware(...middleware),
...enhancers
)
)

I am getting error :Uncaught Error: Expected the enhancer to be a function

最佳答案

您将两个 reducer 传递给 createStore 函数而不是一个。

由于 createStore 的第三个参数始终是增强函数,它认为“initiaeState”变量是增强函数,因为您将其作为 thid 参数传递给 createStore。

createStore 期望收到以下参数:

  1. reducer (Function): A reducing function that returns the next statetree, given the current state tree and an action to handle.

  2. [preloadedState] (any): The initial state. You may optionallyspecify it to hydrate the state from the server in universal apps,or to restore a previously serialized user session. If you producedreducer with combineReducers, this must be a plain object with thesame shape as the keys passed to it. Otherwise, you are free to passanything that your reducer can understand.

  3. [enhancer] (Function): The store enhancer. You may optionallyspecify it to enhance the store with third-party capabilities suchas middleware, time travel, persistence, etc. The only storeenhancer that ships with Redux is applyMiddleware().

请记住,您应用中的根 reducer 应将所有 reducer 合并为一个 reducer 。

来自Redux docs

First and foremost, it's important to understand that your entireapplication really only has one single reducer function

关于reactjs - Uncaught Error : Expected the enhancer to be a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41299725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com