以下のようなコンポーネント構造を持つ1つのアプリケーションがあります。 {this.props.children}を使用して、すべてのコンポーネントのヘッダをロードコンポーネントアプリメイン親 コンポーネントヘッダー コンポーネントホーム コンポーネントダッシュボード コンポーネントデータ コンポーネントDATALOADreact.js多段コンポーネント内に小道具と状態を入れよう
アプリケーションはヘッダに含まれているが、いくつかの状態変数を渡すレンダリング。 ホームには、ヘッダーを更新するためにAppの状態変数を更新するアクションを持つDashboardが含まれています。 データにはここからもDataLoadが含まれています。ヘッダーを更新するには、Appの状態変数を更新する必要があります。
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;
これをチェックしてください(http://stackoverflow.com/questions/32370994/how-to-pass-props-to-this -props-children)。 –
[{this.props.children}に小道具を渡す方法]の複製があります(http://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-children) –