components in react code example
Example 1: create react component class
class MyComponent extends React.Component{
constructor(props){
super(props);
};
render(){
return(
My First React Component!
);
}
};
Example 2: class app extends component syntax
class Welcome extends React.Component {
render() {
return Hello, {this.props.name}
;
}
}
Example 3: react functional components
const component = () => {
console.log("This is a functional Component");
}
Example 4: react component
/* React Component Template */
export default class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
//state properties here
};
}
render() {
return (
);
}
}
Example 5: React Components
class Car extends React.Component {
render() {
return Hi, I am a Car!
;
}
}
Example 6: create-react-app class component
npx create-react-app my-app --scripts-version [email protected]