I want to update the state of a React component every 1000 ms. However, I tried doing setInterval on the componentDidMount, but with no luck. Currently I get two results in my console.log, the one is an empty state object in the constructor, and the other is the fetched object from the API. How do I update the state of the component every 1000 ms with setInterval?
This is my code:
let url = 'some-link-bla-bla';
class Basemap extends React.Component {
constructor(props) {
super(props);
this.state = {};
console.log(this.state);
}
render() {
return (
<Scene style={{ width: '100vw', height: '100vh' }}
mapProperties={{ basemap: 'satellite' }}
viewProperties={ this.state } />
);
}
componentDidMount() {
fetch(url)
.then(d => d.json().then(function(d) {
console.log(d);
}))
.then(d => function(d) {
this.setState({
center: [
{latitude : d.iss_position.latitude} + ', ' +
{longitude: d.iss_position.longitude}
]
})
});
}
}
export default Basemap;
setInterval. Your code has none