reactを使って開発しているのですが、
詰まってしまったので知恵をお貸しください。
##やろうとしていること
component1(親)
this.state = ( hoge: false ); func() { this.setState({ hoge: true }); } render() { return ( <div> <component2 testProps={this.state} /> <component3 testFunc={this.func} /> </div> ); }
component2(子)
static propTypes = { testProps: PropTypes.bool } this.state = ( test: this.props.testProps.hoge, ); render() { if(this.state.test) { return ( <p>成功</p> ); } else { return ( <p>失敗</p> ); } }
component3(子)
const propTypes = { testFunc: PropTypes.func } render() { return ( <button onClick={() => { this.props.testFunc(); }}>aaa</button> ); }
component2はstateの値がtrueだったら成功、falseだったら失敗を出すようにしています。
component3のボタンをクリックしたら親のcomponent1のstateを変更し、hogeをtrueにします。
そしたらcomponent2で出てくる値は成功になるはずなのですが
変わりません。
stateの値は変わっているのですがview上では変化はありません。
どうすれば変化するのでしょうか?
過去の質問が未解決のまま放置になっているようです。過去の質問で解決済みになったものがありましたら、ベストアンサーを選択し解決済みに変更頂けますでしょうか?
回答1件
あなたの回答
tips
プレビュー