2017-06-06 13 views
-2

次のようなdivがあります。reactjsを使用してコンポーネント間でデータを渡す

<div className="horiz_center" onClick={this.textType.bind(this,'text')}> 
    <img src={StarIcon} className="post_type_icon"/> 
    <a className="post_type_text">Text</a> 
</div> 

私は私の質問は、私は別のコンポーネントでpostTypeを使用する場合、どのように私は、そのコンポーネントに渡すことができている

textType(postType) { 

     this.setState({postType}); 

} 

この関数で値を得ることができますか?

+0

のようなあなたのプロパティにアクセスします。もっと読む[ここ](https://facebook.github.io/react/docs/components-and-props.html) – ickyrr

答えて

0
const {postType} = this.state; 
<MyComponent postType={postType} /> 

そして、あなたのコンポーネント内(MyComponent)あなたは `そのためprops`を使用

this.props.postType 
関連する問題