I can't manage to dynamically produce more than one 'Card' in my React webpage. I import the data from database.js, but I'm clearly not implementing the For loop correctly.
I've tried the loop in a function outside the render() but that didn't work. I need the for loop to produce however many objects I have in the database, but I'm stuck on one. I can call the data within the {} in the thml code, but that's about it.
projects.js
class Projects extends Component {
constructor(props) {
super(props);
this.state = { activeTab: 1 };
}
toggleCategories() {
if (this.state.activeTab === 1) {
for (let data of database) {
return (
<div className='projects-grid'>
<Card shadow={4} style={{ minWidth: '450', margin: 'auto' }}>
<CardTitle style={{height: '250px', background: data.image }}></CardTitle>
<CardText>
{data.name}
</CardText>
<CardActions border>
<Button colored>GitHub</Button>
<Button colored>Live Demo</Button>
</CardActions>
</Card>
</div>
)
}
}```
**database.js**
let database = [
{
name: 'Trombinoscope',
image: 'url(https://i.ibb.co/g4mT3K5/html-Css-Js.jpg)',
description: 'Group project',
languages: 'HTML, CSS, JavaScript'
},
{
name: 'CRUD System',
image: 'url(https://i.ibb.co/g4mT3K5/html-Css-Js.jpg)',
description: 'Video game database',
languages: 'PHP, SQL'
}
]
export default database;
Any help would be appreciated.
returnon the first loop iteration, which stops the loop. IstoggleCategoriessupposed to render all of those cards?toggleCategoriesis used to select which type of project I will show. I'll add an If statement at some point to show just valid data, but I haven't got that far yet.