scrimba
Learn class components in React
Setting state in class components
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

Setting state in class components
AboutCommentsNotes
Setting state in class components
Expand for more info
App.js
run
preview
console
import React from "react"

export default class App extends React.Component {
// const [goOut, setGoOut] = React.useState("Yes")

state = {
goOut: "Yes"
}

toggleGoOut() {
setGoOut(prevState => {
return prevState === "Yes" ? "No" : "Yes"
})
}

render() {
return (
<div className="state">
<h1 className="state--title">Should I go out tonight?</h1>
<div className="state--value" onClick={this.toggleGoOut}>
<h1>{this.state.goOut}</h1>
</div>
</div>
)
}
}
Console
/index.html
-6:17