DEV Community

Discussion on: How to convert a React Class Component to a Function Component

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

Thanks, Seb! You just gave me the best (simplified) explanation of React Hooks ever:
Instead of...

constructor(props) {  
  super(props);  
  this.state = {  
    counter: 0,  
    name: ""  
  }  
}  

...use this:

function MyComponent(props) {  
  const [counter,setCounter] = useState(0);  
  const [name,setName] = useState("");  
}
Collapse
 
sebtoombs profile image
Seb

😀 so happy to help! If just one person finds my post helpful, thats a massive win for me!