gpt4 book ai didi

reactjs - 类型错误 : middleware is not a function

转载 作者:行者123 更新时间:2023-12-03 13:02:02 25 4
gpt4 key购买 nike

我正在尝试在我的reactjs应用程序中应用redux。由于这些错误,我无法继续:

enter image description here

enter image description here

我确信我已经安装了我需要的所有依赖项。这是我的 package.json 的相关部分

"dependencies": {
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-promise": "^0.5.3",
"redux-thunk": "^2.2.0",
}

这是我的 index.js 中实现 redux 的部分

import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import reducers from './reducers';

const logger = createLogger();
const store = createStore(reducers,
applyMiddleware(
thunkMiddleware, logger
)
)

ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);

最佳答案

根据docs您混淆了 redux-logger

的用法

您需要导入特定的createLogger函数

import { createLogger } from 'redux-logger'

const logger = createLogger({
// ...options
});

或者使用默认导入

import logger from 'redux-logger'

然后你的代码应该没问题

const store = createStore(
reducers,
applyMiddleware(thunkMiddleware, logger)
)

关于reactjs - 类型错误 : middleware is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46869671/

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