简体   繁体   English

Reactjs将函数props传递给component&#39;addrow` on的无效值 <div> 标签。 从元素中删除它

[英]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.

相关问题 反应:道具`savehere`的值无效<div>标签。 从元素中删除它,或者传递一个字符串或数字值以将其保留在 DOM 中 - React: Invalid value for prop `savehere` on <div> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM 如何解决“警告:未知道具`change-background`,`colorcode`的问题 <div> 标签。 从元素中删除这些道具”错误? - How to fix “Warning: Unknown props `change-background`, `colorcode` on <div> tag. Remove these props from the element” error? 如何修复“警告:未知的道具`ng-app`在 <body> 标签。 从元素中删除该道具”错误? - How to fix “Warning: Unknown prop `ng-app` on <body> tag. Remove this prop from the element” error? 修复 React 警告:&lt;&gt; 标签上的未知道具。 从元素中移除这个道具 - Fix React Warning: Unknown prop on <> tag. Remove this prop from the element 如何避免标签上出现错误“未知道具&lt;&gt;。 从元素中删除该道具”? - How to avoid the error “Unknown prop <> on tag. Remove this prop from the element”? 警告:未知道具`input`,`meta`<input> 标签。 从元素中删除这些道具 - Warning: Unknown props `input`, `meta` on <input> tag. Remove these props from the element reduxForm 7.0.4未知道具`input`,`meta` on <input> 标签。 从元素中移除这些道具 - reduxForm 7.0.4 Unknown props `input`, `meta` on <input> tag. Remove these props from the element 在 reactjs 中将组件作为道具传递 - pass component as prop in reactjs 在 Reactjs 中将组件作为道具传递 - Pass component as a prop in Reactjs 道具Griddle自定义组件中的传递函数-ReactJS - Pass function in props Griddle custom component - ReactJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM