scrimba
Frontend Career Path
React basics
Meme generator
Boxes challenge part 3.1 - local 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

Boxes challenge part 3.1 - local state
AboutCommentsNotes
Boxes challenge part 3.1 - local state
Expand for more info
Box.js
run
preview
console
import React from "react"

export default function Box(props) {
/**
* Challenge: Create state controlling whether
* this box is "on" or "off". Use the incoming
* `props.on` to determine the initial state.
*
* Create an event listener so when the box is clicked,
* it toggles from "on" to "off".
*
* Goal: clicking each box should toggle it on and off.
*/
const styles = {
backgroundColor: props.on ? "#222222" : "transparent"
}

return (
<div style={styles} className="box"></div>
)
}
Console
/index.html
"> "> "> "> ">
-4:54