简体   繁体   English

如何避免标签上出现错误“未知道具<>。 从元素中删除该道具”?

[英]How to avoid the error “Unknown prop <> on tag. Remove this prop from the element”?

Please, how can I rewrite this code another way to avoid the error below? 请,我该如何以另一种方式重写此代码,以避免出现以下错误?

     render() {
            const { children, ...props } = this.props;
            return <div {...props} ref={this.setRef}>{children}</div>
      }

I get this error: 我收到此错误:

Unknown prop onClickOutside on tag. 标签上的未知道具onClickOutside Remove this prop from the element. 从元素中删除此道具。 For details ( https://facebook.github.io/react/docs/higher-order-components.html#static-methods-must-be-copied-over ) 有关详细信息( https://facebook.github.io/react/docs/higher-order-components.html#static-methods-must-be-copied-over

Native DOM elements only allowed to have Native DOM attributes. 仅允许本机DOM元素具有本机DOM属性。 You can't pass any attribute (prop) you want. 您不能传递所需的任何属性(属性)。
If you know what valid props you need to this element you can destruct them out of props and pass them explicit. 如果您知道此元素需要什么有效道具,则可以将它们从道具中破坏出来,并显式传递它们。
For example: 例如:

 render() {
            const { children, onClickOutside } = this.props;
            return <div onClick={onClickOutside} ref={this.setRef}>{children}</div>
      }

You can simply remove in from the ...props you transfer: 您可以简单地从转移的...props删除:

render() {
            const { children, onClickOutside, ...props } = this.props;
            return <div {...props} ref={this.setRef}>{children}</div>
      }

If you want onClickOutside to map to the onClick of the div , then handle this explicitly: 如果您希望onClickOutside映射到divonClickonClickOutside明确处理此问题:

render() {
            const { children, onClickOutside, ...props } = this.props;
            return <div {...props} onClick={onClickOutside} ref={this.setRef}>{children}</div>
      }

Any version of React < 16.x, have a whitelist of available attributes. 任何版本的React <16.x,都有可用属性的白名单。 So, all attributes passed to elements must be in the whitelist. 因此,传递给元素的所有属性都必须在白名单中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复“警告:未知的道具`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 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 反应:道具`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 未知道具“可选”开启 <table> 标签。 在Material UI中 - Unknown prop `selectable` on <table> tag. in Material UI 如何解决“警告:未知道具`change-background`,`colorcode`的问题 <div> 标签。 从元素中删除这些道具”错误? - How to fix “Warning: Unknown props `change-background`, `colorcode` on <div> tag. Remove these props from the element” error? 警告:未知道具`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 Redux-如何从状态中删除道具? - Redux - How to remove a prop from the state? 如何从 JointJS 元素中的道具读取值? - How to read value from prop in JointJS element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM