[英]this.props is not a function (reactjs)
Have a code that delete element by request 有一个通过请求删除元素的代码
class ArchOrDlt extends Component{
constructor(props) {
super(props)
}
deleteItem(itemId, e) {
console.log(itemId);
this.props.test();
this.props.DeleteListProfileItem(itemId);
}
ArchOrDlt() {
const isdel = this.props.isdel;
const itemId = this.props.itemId;
if (isdel == 1) {
return (<div><a onClick={this.deleteItem.bind(this, itemId)} >delete</a></div>);
}
return (<div>archived</div>);
}
render() {
return (
<div>
{this.ArchOrDlt()}
</div>
);
}
}
If I press link I get Uncaught TypeError: this.props.test is not a function 如果按链接,我会收到Uncaught TypeError:this.props.test不是函数
There I dispatch to props 我在那里派遣道具
const mapDispatchToProps = function(dispatch) {
return {
IncomeListProfile: () => dispatch(IncomeProfileList()),
DeleteListProfileItem: (id) => dispatch(DeleteListProfileItem(id)),
openPopUp: () => dispatch(openPopUp()),
test: () => dispatch(test())
}
}
Can't Understand Why it's happen for exaple if I move this.props.test(); 如果我移动this.props.test();无法理解为什么会发生这种情况。 to another click, everything working fine, there full component https://plnkr.co/edit/OEugCIxoAGE8iVb57WOa?p=catalogue
再次单击,一切正常,有完整的组件https://plnkr.co/edit/OEugCIxoAGE8iVb57WOa?p=catalogue
First of all, you should use bindActionCreators function from redux 首先,您应该使用redux中的bindActionCreators函数
import { bindActionCreators } from 'redux';
...
const mapDispatchToProps = (dispatch) => {
return {
IncomeListProfile : bindActionCreators(IncomeProfileList, dispatch),
...
}
}
http://redux.js.org/docs/api/bindActionCreators.html http://redux.js.org/docs/api/bindActionCreators.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.