import React from 'react'; var Parent = React.createClass({ getInitialState:function() { return { display: "none" } }, displayswitch:function() { if(this.state.display == "none") { this.setState({display:"block"}); } else { this.setState({display:"none"}); } }, render:function() { return ( <p onClick={this.displayswitch}>btn</p> ); } }); export default Personal;
上記でこのコンポーネント内でdisplayのスイッチングはできたのですが、
このstateを子コンポーネントでも取得したいのですがどうすればよいでしょうか?
import React from 'react'; import Child from './Child.js'; var Parent = React.createClass({ getInitialState:function() { return { display: "none" } }, displayswitch:function() { if(this.state.display == "none") { this.setState({display:"block"}); } else { this.setState({display:"none"}); } }, render:function() { return ( <Child /> ); } }); export default Personal;
Childの方でstateの値を取得したいです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/06 11:20 編集
2018/02/06 12:23