scrimba
Meta scrims
React Advanced
Lab Solution: Managing state within a component
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

Lab Solution: Managing state within a component
AboutCommentsNotes
Lab Solution: Managing state within a component
Expand for more info
src
App.js
run
preview
console
import { useState } from "react";

export default function App() {
const [giftCard, setGiftCard] = useState(
{
firstName: "Jennifer",
lastName: "Smith",
text: "Free dinner for 4 guests",
valid: true,
instructions: "To use your coupon, click the button below.",
}
);

function spendGiftCard() {

}

return (
<div style={{padding: '0px 20px'}}>
<h1>
Gift Card Page
</h1>
<h2>
Customer: {giftCard.firstName} {giftCard.lastName}
</h2>
<h3>
{giftCard.text}
</h3>
<p>
{giftCard.instructions}
</p>
{
giftCard.valid && (
<button onClick={spendGiftCard}>
Spend Gift Card
</button>
)
}
</div>
);
}
Console
/public/index.html
-2:29