Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用reactjs在组件之间传递数据_Reactjs_Components - Fatal编程技术网

使用reactjs在组件之间传递数据

使用reactjs在组件之间传递数据,reactjs,components,Reactjs,Components,我有一个像下面这样的部门 <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,如何将其

我有一个像下面这样的部门

<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
,如何将其传递给该组件?

您可以使用
props
来实现这一点。多读点
const {postType} = this.state;
<MyComponent postType={postType} />
const {postType} = this.state;
<MyComponent postType={postType} />
this.props.postType