我是新来的react-redux,我正在使用react-thunk中间件。每当我尝试运行我的动作创建者时(通过按下我的按钮),我都会收到错误“Uncaught TypeError:dispatch不是函数”。任何人都知道发生了什么事?调度不是函数TypeError
的src /动作/ index.js
function editUserName (newUserName) {
return {
type: 'CHANGE_USER_NAME',
newUserName: newUserName
}
}
export function editUserNameDelegate() {
return function (dispatch, getState) {
return dispatch(editUserName("thunkUser"))
}
}
的src /集装箱/ admin.js
import { editUserNameDelegate } from '../actions/index'
...
<input type="button" onClick={ editUserNameDelegate() } value="edit UserName" />
return function(dispatch,getState){ return dispatch(editUserName(“thunkUser”)) }在这个函数中,你已经将dispatch作为参数,并在第二行作为函数处理? – Shubhranshu