【发布时间】:2017-06-12 17:27:40
【问题描述】:
我是 react-redux 的新手,我正在使用 react-thunk 中间件。每当我尝试运行我的动作创建器(通过按下我的按钮)时,我都会收到错误“Uncaught TypeError:dispatch is not a function”。有谁知道怎么回事?
src/actions/index.js
function editUserName (newUserName) {
return {
type: 'CHANGE_USER_NAME',
newUserName: newUserName
}
}
export function editUserNameDelegate () {
return function (dispatch, getState) {
return dispatch(editUserName("thunkUser"))
}
}
src/containers/admin.js
import { editUserNameDelegate } from '../actions/index'
...
<input type="button" onClick={ editUserNameDelegate() } value="edit UserName" />
【问题讨论】:
-
return function (dispatch, getState) { return dispatch(editUserName("thunkUser")) } 在此函数中,您将 dispatch 作为参数,在第二行中将其视为函数???
标签: javascript reactjs redux react-redux redux-thunk