[React Fundamentals] Introduction to Properties

This lesson will teach you the basics of setting properties in your React components.

class App extends React.Component {
  render(){
    let txt = this.props.txt
    return <h1>{txt}</h1>
  }
}

App.propTypes = {
  txt: React.PropTypes.string,
  cat: React.PropTypes.number.isRequired
}

App.defaultProps ={
  txt: 'this is the default txt'
}

ReactDOM.render(
  <App cat={5} />,
  document.getElementById('app')
);
原文地址:https://www.cnblogs.com/Answer1215/p/5769429.html