new as of spring 2019
but first...
const arr = [10,12,13,14]
const [first, second] = arr
const first = arr[0]
const second = arr[1]
console.log(first) // will log out 10
console.log(second) // will log out 12
// Bonus:
const [firstValue, secondValue, ...theRest] = arr
const firstValue = arr[0]
const secondValue = arr[1]
const theRest = arr.slice(2)
const Person = () => {
const [cupsOfCoffee, setCupsOfCoffee] = useState(0)
return (
<div>
<h1>Good Morning!</h1>
<h2>I have had {cupsOfCoffee} today.</h2>
</div>
);
}
const Person = () => {
const [cupsOfCoffee, setCupsOfCoffee] = useState(0)
return (
<div>
<h1>Good Morning!</h1>
<h2>I have had {cupsOfCoffee} today.</h2>
<button onClick={() => setCupsOfCoffee(cupsOfCoffee + 1)}>drink</button>
</div>
)
}