Created
April 21, 2021 21:27
-
-
Save richleach/a059d1b6f42aac95ca56a6f2478f98e1 to your computer and use it in GitHub Desktop.
Looping over data stuff in JS/React is always done with array.map. Don't forget the key!
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
import React from 'react'; | |
function myTest() { | |
const dummyData = [ | |
{id: 1, title: 'Title 1', image: 'www.image.com/1', desc: 'Description 1'}, | |
{id: 2, title: 'Title 2', image: 'www.image.com/2', desc: 'Description 2'}, | |
{id: 3, title: 'Title 3', image: 'www.image.com/3', desc: 'Description 3'} | |
]; | |
return ( | |
<> | |
<ul> | |
{dummyData.map(item => { | |
return <li key={item.id}>{item.title}</li> | |
})} | |
</ul> | |
</> | |
) | |
} | |
export default MyTest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment