当我从事儿童工作的道具未知道具警告
Unknown prop
接近on <h3> tag. Remove this prop from the element.
我发现了一个错误。
我创建了一个母块:
var Block = React.createClass({
getInitialState: function() {
return {open: true}
},
close: function() {
this.setState({open: false});
},
render: function() {
var childrenWithProps = React.Children.map(this.props.children, function(child) {
return React.cloneElement(child, {
close: this.close
})
}.bind(this));
return (
<div>
{childrenWithProps}
</div>
)
}
});
而在另一个组件使用它:
var Elm = React.createClass({
render: function() {
return (
<Block>
<h3>Hi</h3>
<button type="button" onClick={this.props.close}>Close</button>
</Block>
)
}
});
我知道这是因为<h3>
没有close
,但button
有它。
我该如何解决?
谢谢。
谢谢。我想创建一个我可以在任何地方使用的Popup组件。它可以有很多孩子。孩子们可以关闭它。 – Fijir
然后你应该照我说的去做:在'Block'定义中定义'
的下面。是的,但'button'就是例子。我可以有一个应该关闭Popup的元素。例如,一些链接“关闭弹出”或一些行动后... – Fijir