1// convert a class component to a functional component
2class MyComponent extends React.Component {
3 state: {
4 name: 'Bob'
5 }
6 render() {
7 return (
8 <p>Hello, my name is {this.state.name}</p>
9 );
10 }
11}
12
13const MyComponent = () => {
14 const [name, setName] = React.useState('Bob');
15 return (<p>Hello, my name is {name}</p>);
16}