react组件父传子

react组件父传子,子组件使用父组件的数据,用props

import React, { Component } from 'react';

class App extends Component {
  constructor(props){
    super(props);
    this.state = {
      arr :[1,2,3]  // 父组件数据
    }
  }
  render() {
    return (
      <div>
        {/* 父组件直接使用this.state */}
        <div>{this.state.arr}</div>
        {/* 把父组件数据绑定到子组件中 */}
        <Test content={this.state.arr}></Test>
      </div>
    );
  }
}
class Test extends Component {
  render(){
    return (
      <div>
        {/* this.props获取父组件数据 */}
        <div>{this.props.content}</div>
      </div>
    )
  }
}
export default App;
原文地址:https://www.cnblogs.com/luguankun/p/10272356.html