class to functional component react

Solutions on MaxInterview for class to functional component react by the best coders in the world

showing results for - "class to functional component react"
Fabiana
25 Aug 2017
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}