[英]Reactjs pass function props to component Invalid value for prop `addrow` on <div> tag. Either remove it from the element
I'm trying to pass a function to a component, but I'm having the following problem: 我正在尝试将函数传递给组件,但我遇到以下问题:
"Reactjs pass function props to component Invalid value for prop addrow
on tag. Either remove it from the element, or pass a string or number value to keep it in the DOM." “Reactjs将函数props传递给组件在标签上的prop
addrow
无效值。要么从元素中删除它,要么传递字符串或数字值以将其保留在DOM中。”
Code: 码:
constructor(props) {
super(props);
this.props = props;
this.addRows = this.addRows.bind(this);
}
addRows() {
console.log("AddRows")
}
<CreateQrModal
show={modalAdd}
onHide={this.modalAddClose}
addrow={this.addRows}
/>
Component: 零件:
handleSubmit() {
this.props.addrow()
}
from your code snippet.. 来自你的代码片段..
change this.props.onRow()
to this.props.addrow()
.. it seems you mistyped the name. 将
this.props.onRow()
更改为this.props.addrow()
..您似乎错误输入了名称。
Also you can get around the binding by using Arrow function syntax 您还可以使用箭头函数语法绕过绑定
so addRow = () => {...}
.. then you don't have to manually bind the function to the component in the constructor. 所以
addRow = () => {...}
..那么你不必手动将函数绑定到构造函数中的组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.