defaultProps (ok)

https://freetuts.net/props-validation-trong-reactjs-2376.html

import React from "react";
 
class App extends React.Component {
  render() {
    const {number1, number2} = this.props
    return (
      <div>
        <h1>{number1} + {number2} = {number1 + number2}</h1>
      </div>
    );
  }
}
//Chỉ định props mặc định.
//Ở đây mình cho props number1, number2 là kiểu int
App.defaultProps = {
  number1: 4,
  number2: 2
}
export default App;

Last updated

Was this helpful?