scrimba
Frontend Career Path
React basics
Meme generator
Complex state: arrays
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

AboutCommentsNotes
Complex state: arrays
Expand for more info
index.js
run
preview
console
import React from 'react';
import ReactDOM from 'react-dom';

function App() {
/**
* Challenge: Convert the code below to use an array
* held in state instead of a local variable. Initialize
* the state array with the same 2 items below
*
* Don't worry about fixing `addItem` quite yet.
*/
const thingsArray = ["Thing 1", "Thing 2"]

function addItem() {
// We'll work on this next
// const newThingText = `Thing ${thingsArray.length + 1}`
// thingsArray.push(newThingText)
// document.getElementById()
// console.log(thingsArray)
}

const thingsElements = thingsArray.map(thing => <p key={thing}>{thing}</p>)

return (
<div>
<button onClick={addItem}>Add Item</button>
{thingsElements}
</div>
)
}

ReactDOM.render(<App />, document.getElementById('root'));
Console
/index.html
-10:28