使用 redux-thunk 时出现 TypeError: middleware is not a function 错误是什么原因?

问题描述 投票:0回答:1

我需要使用 redux-thunk 中间件,但是当我将其作为参数传递给

applyMiddleware
函数时,它显示以下错误:

return middleware(middlewareAPI);
               ^

TypeError: middleware is not a function

这是我使用 thunk 的代码片段:

import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import reducer from "./reducers.js";

const store = createStore(reducer, applyMiddleware(thunk))

导致此错误的问题是什么?

javascript redux middleware redux-thunk
1个回答
0
投票

使用以下代码代替 thunk

const thunkMiddleware = require('redux-thunk').thunk
© www.soinside.com 2019 - 2024. All rights reserved.