class T1 extends React.Component
{
constructor(props)
{
super(props)
this.state={
value:1
}
this.handleChange=this.handleChange.bind(this)
}
handleChange(i,event)
{
this.setState({
value:i
})
console.log(this.state)
}
render()
{
return (<T3 change={this.handleChange}/>)
}
}
class T3 extends React.Component
{
handleChange(e)
{
const v=Math.random()*10;
this.props.change(v)
}
render()
{
return (<div>
<button onClick={(e)=>this.handleChange(e)}>
T3onClick
</button>
</div>)
}
}
ReactDOM.render(
<div>
<T1/>
</div>
, document.getElementById('root'));
先把事件在父组件准备好 function(value,e) 作为props.change传给子组件
子组件就能在需要的地方调用this.props.change(value) 实现value传过去且更新了父组件的state
标签:传递,render,value,react,state,事件,props,组件,handleChange From: https://blog.51cto.com/u_11889343/6046981