react component or function code example
Example 1: react component example
const element = <div />;
Example 2: react function component
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
Example 3: class to functional component react
class MyComponent extends React.Component {
state: {
name: 'Bob'
}
render() {
return (
<p>Hello, my name is {this.state.name}</p>
);
}
}
const MyComponent = () => {
const [name, setName] = React.useState('Bob');
return (<p>Hello, my name is {name}</p>);
}