scrimba
Learn React for free
useState() Part 2 - Changing State
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

useState() Part 2 - Changing State
AboutCommentsNotes
useState() Part 2 - Changing State
Expand for more info
App.js
run
preview
console
import React from "react"

// Convert the class below to a functional component that uses the useState hook to initalize a count vartiable to 0 and display the count on the screen.
// Don't worry about the part where the button changes the count quite yet, that's what you're here to learn about!

class App extends React.Component {
constructor() {
super()
this.state = {
count: 0
}
}

render() {
return (
<div>
<h1>{this.state.count}</h1>
<button>Change!</button>
</div>
)
}
}

export default App
Console
/index.html
-7:45