Fel*_*tos 5 reactjs react-proptypes
我在使用React propTyoes时遇到问题。正如您在下面的代码中看到的那样,我创建了一个需要2个道具才能工作的组件。
当我在App文件中使用该组件时,仅传递了1个属性,而没有“ stateSidebarVisible”,它不会抛出任何错误/警告反应...(我阅读了很多有关NODE_ENV生产/开发的信息,在我的节点中搜索process.env,但没有找到NODE_ENV变量)。有什么线索吗?
FFMainHeader
export default class FFMainHeader extends React.Component {
render() {...}
}
FFMainHeader.propTypes = {
stateSidebarVisible: React.PropTypes.bool.isRequired,
handleSidebarChange: React.PropTypes.func.isRequired
};
Run Code Online (Sandbox Code Playgroud)
应用程式
这是我所谓的FFMainHeader组件。
export default class FFMainApp extends React.Component {
.......
render() {
return (
<div id="FFMainApp">
<FFMainHeader
handleSidebarChange={this.onSidebarChange} />
<FFMainSidebar />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
export default class FFMainHeader extends React.Component {
constructor(props) {
super(props);
this.clickSidebarChange = this.clickSidebarChange.bind(this);
}
clickSidebarChange(e) {
e.preventDefault();
(this.props.stateSidebarVisible) ?
this.props.stateSidebarVisible = false :
this.props.stateSidebarVisible = true;
this.props.handleSidebarChange(this.props.stateSidebarVisible);
}
render() {
return (
<header id="FFMainHeader">
<a href="#" onClick={this.clickSidebarChange}>
Abre/Fecha
</a>
</header>
);
}
}
FFMainHeader.propTypes = {
stateSidebarVisible: React.PropTypes.bool.isRequired,
handleSidebarChange: React.PropTypes.func.isRequired
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1189 次 |
| 最近记录: |