import React from 'react'; const SERVER_URL = 'http://localhost:3000/' export default class Site extends React.Component { state = { classes: [], psboard: [], componentMounted: false } callAPI = (targetUrl) => { let url = SERVER_URL + 'api/data/'+ targetUrl let data = "" console.log(url); fetch(url) .then(response => response.json()) .then(body => this.setState({ [targetUrl]: body })); } componentDidMount() { this.callAPI('classes') this.callAPI('psboard') } render() { console.log(this.state) return (
Upcoming Classes
{this.state.psboard.map((item, i) =>
{item.subject}
{item.date}
)}
Posts
); } }