scrimba
Learn class components in React
Constructor method 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

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

export default class App extends React.Component {
state = {
goOut: "Yes"
}

toggleGoOut = () => {
this.setState(prevState => {
return {
goOut: prevState.goOut === "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
-7:55