scrimba
Learn React
Meme generator
Complex state: objects
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

Complex state: objects
AboutCommentsNotes
Complex state: objects
Expand for more info
App.js
run
preview
console
import React from "react"

export default function App() {
const [contact, setContact] = React.useState({
firstName: "John",
lastName: "Doe",
phone: "+1 (719) 555-1212",
email: "itsmyrealname@example.com",
isFavorite: false
})
/**
* Challenge: Fill in the values in the markup
* using the properties of our state object above
* (Ignore `isFavorite` for now)
*/

function toggleFavorite() {
console.log("Toggle Favorite")
}

return (
<main>
<article className="card">
<img src="./images/user.png" className="card--image" />
<div className="card--info">
<img
src={`../images/star-empty.png`}
className="card--favorite"
onClick={toggleFavorite}
/>
<h2 className="card--name">
John Doe
</h2>
<p className="card--contact">+1 (719) 555-1212</p>
<p className="card--contact">itsmyrealname@example.com</p>
</div>

</article>
</main>
)
}
Console
/index.html
-3:58