2017-06-06 63 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> 

我可以使用此功能

textType(postType) { 

     this.setState({postType}); 

} 

我的问题是,如果我想在另一个组件使用postType的价值,我怎样才能把它传递给该组件?

+0

您使用'props'了点。尝试阅读更多[这里](https://facebook.github.io/react/docs/components-and-props.html) – ickyrr

回答

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

而在你的组件(MyComponent)访问您的属性,如

this.props.postType