scrimba
Learn React
Meme generator
Passing state as props
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

Passing state as props
AboutCommentsNotes
Passing state as props
Expand for more info
App.js
run
preview
console
import React from "react"

export default function App() {
const [count, setCount] = React.useState(0)

function add() {
setCount(prevCount => prevCount + 1)
}

function subtract() {
setCount(prevCount => prevCount - 1)
}

/**
* Challenge:
* - Create a new component named Count
* - It should receive a prop called `number`, whose value
* is the current value of our count
* - Have the component render the whole div.counter--count
* and display the incoming prop `number`
* - Replace the div.counter--count below with an instance of
* the new Count component
*/
return (
<div className="counter">
<button className="counter--minus" onClick={subtract}>–</button>
<div className="counter--count">
<h1>{count}</h1>
</div>
<button className="counter--plus" onClick={add}>+</button>
</div>
)
}
Console
/index.html
-5:52