I've created a webpage that pools from a SQL database I generated that has info such as a person's name, address and job. I figured out how to display this on the webpage by creating an array and putting the data into it to then return. What I want to do is create a react component that looks like a tile/nametag and is a box containing each person/job and have it be created for each entry. I am confused on how I would create the react component and style it with CSS.
here is my webpage code:
import React, { Component } from "react";
export class Dashboard extends Component {
displanyName = Dashboard.name;
constructor(props) {
super(props);
this.state = {
people: []
};
}
componentDidMount() {
fetch("api/people")
.then(response => response.json())
.then(data => this.setState({ people: data }));
}
render() {
//const { people } = this.state; // equivalent to next line
const people = this.state.people;
if (people.length > 0)
//creates an array to iterate
let arr = people.map((person, index) => <div key={index}>Person: {person.name} , Job: {person.job}</div>);
return (
<div>
{arr}
</div>
);
}
}
That displays the contents of the array on the page like this: Person: Bob Bobbert , Job: Programmer Person: Jane Doe , Job: Teacher Person: John Smith , Job: Chef