react 获取子组件数据

1 子组件添加ref属性

<Child ref ='demo'>

父组件调用this.refs.demo.statethis.refs.demo.props

2 子组件添加事件属性

<Child onRef={ref => this.child=ref}>

子组件内调用onRef

componentDidMount() {
    this.props.onRef(this)
}

父组件调用this.child.statethis.child.props

注意:即使父组件引用了child.state中的数据,子组件state的更新也不会引起父组件的重新渲染

猜你喜欢

转载自blog.csdn.net/weixin_43915401/article/details/112966898
今日推荐