【发布时间】:2018-10-28 18:05:05
【问题描述】:
我正在用下面的 actionCreator 附加dispath
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(Object.assign({},basicActions), dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(NewClientSetup);
并像这样调用 actionCreator 函数
componentCallback:text => actions(basicActions.selectOption(text))
这是 basicActions.js
export function selectOption(text){
debugger;
const actionObj = {
type: types.SELECT_OPTION,
id: nextActionId++,
text
};
return actionObj;
}
export function requestSuccess(){
console.log('inside requestSuccess');
return {type:'SUCCESS',id:1}
}
export function fetchS1Users(parentUserId){
debugger;
axios.get(url, {
params: {
parentUserVal: parentUserId
},
responseType: 'json'
})
.then(function (response) {
console.log('res '+response.data);
console.log('res JSON '+JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
return {
id: nextActionId++,
type: types.FETCH_USERS,
inputParam: parentUserId,
s1users:{}
}
}
但它给出的错误'Uncaught TypeError:actions is not a function'
这确实有效
actions: bindActionCreators(basicActions.selectOptions, dispatch)
【问题讨论】:
标签: reactjs redux redux-thunk