當我從事兒童工作的道具未知道具警告
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