Skip to content

Instantly share code, notes, and snippets.

@richleach
Created April 21, 2021 21:27
Show Gist options
  • Save richleach/a059d1b6f42aac95ca56a6f2478f98e1 to your computer and use it in GitHub Desktop.
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!
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