Created
November 27, 2021 10:46
-
-
Save jacobdo2/999113d520635bf0996555938d9f96db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function Parent() { | |
const [items, setItems] = useState([]); | |
const handleSetItems = () => { | |
setItems((prevItems) => { | |
return [ | |
...prevItems, | |
...new Array(10).fill("").map((_, index) => ({ | |
name: `Some item ${index + prevItems.length}`, | |
})) | |
]; | |
}); | |
}; | |
return ( | |
<div className="App"> | |
<button onClick={handleSetItems}>Add items</button> | |
{items.map((item, index) => (<div key={item.name}>{item.name}</div>))} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment