I have symfony rest api and I'm writing some frontend for this (1st time using react). So, here is my index.js:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
class App extends Component {
constructor(props) {
super(props);
this.state = {
visits: []
};
}
componentDidMount() {
const url = 'http://localhost/app.php/api/visits?from=2017-05-05&to=2017-05-08';
axios.get(url)
.then(response => response.json())
.then(
visits => this.setState({visits})
).catch(err => err)
}
render() {
return (
<div>
<ul>
{this.state.visits.map((visit, index) => <li key={index}>{visit}</li>)}
</ul>
</div>
)
}
}
const app = document.getElementById('app');
ReactDOM.render(<App/>, app);
Response from api looks like:
{
"2017-05-05": 2,
"2017-05-06": 8,
"2017-05-07": 10,
"2017-05-08": 1,
}
How can i iterate through that and print it to the screen? Now i don't get any errors, just getting response from server but don't have anything on the screen.
Greetings