Recap: State & Events
Part of the Fundamentals section of Coddy's React journey — lesson 27 of 42.
Challenge
MediumChapter recap. Build a desk lamp control panel: a counter and a toggle living side by side in one component.
- Add two independent states:
brightnessstarting at0andonstarting atfalse. - Show the brightness in the span with
id="level". Theid="brighter"button adds 1 on every click. - The
id="power"button flipson. When on, show a<p>withid="status"and the textLamp is on; otherwise rendernull.
Try it yourself
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="root"></div>
<script type="module" src="main.jsx"></script>
</body>
</html>All lessons in Fundamentals
2JSX Expressions
Curly BracesMath in BracesBraces in AttributesCalling Functions in JSXRecap: JSX Expressions5State & Events
What Is State?Click CounterCount in StepsToggle with StateIndependent StateRecap: State & Events8Project: Profile Card
Step 1: Card StructureStep 2: Card with PropsStep 3: Like ButtonStep 4: Follow Toggle