Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何避免错误;未知道具<&燃气轮机;标记上。从元素“中移除此道具”;?_Javascript_Reactjs - Fatal编程技术网

Javascript 如何避免错误;未知道具<&燃气轮机;标记上。从元素“中移除此道具”;?

Javascript 如何避免错误;未知道具<&燃气轮机;标记上。从元素“中移除此道具”;?,javascript,reactjs,Javascript,Reactjs,请问,我如何以另一种方式重写此代码以避免下面的错误 render() { const { children, ...props } = this.props; return <div {...props} ref={this.setRef}>{children}</div> } render(){ const{children,…props}=this.props; 返回{children} } 我

请问,我如何以另一种方式重写此代码以避免下面的错误

     render() {
            const { children, ...props } = this.props;
            return <div {...props} ref={this.setRef}>{children}</div>
      }
render(){
const{children,…props}=this.props;
返回{children}
}
我得到这个错误:


标签上的未知属性
onClickOutside
。从元件上拆下此道具。有关详细信息()

您只需从您传输的
…道具中删除:

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

React<16.x的任何版本都有可用属性的白名单。因此,传递给元素的所有属性都必须在白名单中。

您只需从传输的
…道具中删除即可:

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

React<16.x的任何版本都有可用属性的白名单。因此,传递给元素的所有属性都必须在白名单中。

本地DOM元素只允许具有本地DOM属性。您无法传递所需的任何属性(道具)。
如果你知道这个元素需要什么样的有效道具,你可以从道具中解构它们并显式传递它们。
例如:

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

仅允许本机DOM元素具有本机DOM属性。您无法传递所需的任何属性(道具)。
如果你知道这个元素需要什么样的有效道具,你可以从道具中解构它们并显式传递它们。
例如:

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

您是否看到此列表中的
onclickout
?您是否在该列表中看到
onClickOutside