import React from "react"
import Die from "./Die"
export default function App() {
/**
* Challenge: Update the array of numbers in state to be
* an array of objects instead. Each object should look like:
* { value: <random number>, isHeld: false }
*
* Making this change will break parts of our code, so make
* sure to update things so we're back to a working state
*/
const [dice, setDice] = React.useState(allNewDice())
function allNewDice() {
const newDice = []
for (let i = 0; i < 10; i++) {
newDice.push(Math.ceil(Math.random() * 6))
}
return newDice
}
function rollDice() {
setDice(allNewDice())
}
const diceElements = dice.map(die => <Die value={die} />)
return (
<main>
<div className="dice-container">
{diceElements}
</div>
<button className="roll-dice" onClick={rollDice}>Roll</button>
</main>
)
}