zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[React Fundamentals] Introduction to Properties

React to properties Introduction Fundamentals
2023-09-14 09:00:53 时间

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')
);