23 June 2018

ReactJS: Tạo Component với Function hoặc Class

Start project
Component function
ReatcJS 2018
function UserInfo(props){
  return (
    <div>
      <p>Name: {props.name}</p>
      <p>Email: {props.email}</p>
    </div>
  )
}

ReactDOM.render(
  <UserInfo name="Antonio" email="Antonio@gmail.com"/>
  ,document.getElementById('root'));
Component class
ReatcJS 2018
class UserInfo extends React.Component {
  render(){
    return (
      <div>
        <p>Name: {this.props.name}</p>
        <p>Email: {this.props.email}</p>
      </div>
    )
  }
}

ReactDOM.render(
  <UserInfo name="Antonio" email="Antonio@gmail.com"/>
  ,document.getElementById('root'));

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang