Answers for "class to functional component react"

3

class to functional component react

// convert a class component to a functional component
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>);
}
Posted by: Guest on December-04-2020

Code answers related to "class to functional component react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language