react component as function code example

Example 1: create react component class

class MyComponent extends React.Component{
    constructor(props){
        super(props);
    };
    render(){
        return(
            <div>
              <h1>
              	My First React Component!
              </h1>
            </div>
        );
    }
};

Example 2: react class component

class Welcome extends React.Component {
  render() {
    return <h1>Bonjour, {this.props.name}</h1>;
  }
}

Example 3: create-react-app class component

npx create-react-app my-app --scripts-version react-scripts@2.1.7

Example 4: créer composant react

1. Dans le terminal :
npx create-react-app [ nom dossier]
cd [ nom dossier]
npm start

2.désinstaller package :
npm uninstall -g create-react-app