I am new to react. Could someone help me out on how an api call can be made repetitively every 15mins and the data be rendered onto the application? Please find the code below. I think using setInterval/setTimeout could be an option. But, which one is best and please help me out for my code below. Thanks in advance!
import React from 'react';
import axios from 'axios';
export default class UserList extends React.Component {
state = {
users: []
};
componentDidMount() {
axios.get(`https://jsonplaceholder.typicode.com/users`)
.then(res => {
const users = res.data;
this.setState({users});
})
}
render() {
return (
<ul>
{this.state.users.map(user => <li>{user.name}</li>)}
</ul>
)
}
}
setIntervalor else simply introduce a refresh button and make the call when required.setInterval. It's that it was meant for.