react组件传参

父组件向子组件传参

import Son from 'son'

class Father extends Component {
    constructor() {
        super();
        this.state = {
             name : "kaso"
        }
    }

    render() {
        return(
            <div> 
                <Son data = { this.state } />
            </div>
        )
    }
}
  • super原型继承,将this指向该对象
  • constructor自动传入props
  • data = { this.state } 分发下去
class Son extends Component {
    return(
        <h1>{ this.props.data.name }</h1>
    )
}
  • this指代super的对象
  • props为对象名
  • data为传入参数
夹具
原文地址:https://www.cnblogs.com/jilaokang/p/8672358.html