【发布时间】:2017-01-17 07:55:42
【问题描述】:
我有一个具有如下组件结构的应用程序。 Component App Main parent,它使用 {this.props.children} 在所有组件中加载标题 组件头 组件主页 组件仪表板 组件数据 组件数据加载
App 在渲染中包含 Header 并传递一些状态变量。 Home 包含 Dashboard,其中包含更新 App 的状态变量以更新 Header 的操作。 数据包含DataLoad也从这里我需要更新App的状态变量来更新Header。
For example my App is like
import React from 'react';
import Header from './Header.jsx';
class App extends React.Component {
constructor(props) {
super();
this.state = {
show : '1',
}
this.showHide = this.showHide.bind(this);
}
showHideSearch() {
this.setState(prevState => ({
show: prevState.show == '1' ? '0' : '1',
}));
}
render() {
return (
<div>
<Header show={this.state.show}/>
{this.props.children}
</div>
)
}
}
export default App;
import React from 'react';
import Dashboard from './Dashboard.jsx'
class Home extends React.Component {
constructor(props) {
super();
this.showHide = this.showHide.bind(this);
}
showHide() {
tried this but not working
//this.props.showHideSearch();
}
render() {
return (
<div>// this props show not going to dashboard component
<Dashboard show={this.props.show} showHide= {this.showHide.bind(this)}/>
</div>
)
}
}
export default Home;
【问题讨论】:
标签: reactjs