When requesting url: / api / v1 / todos
I set the preloader. The function todo ()
is called inside the todos ()
function. Inside the todo ()
function, the request / api / v1 / todos / $ {todoId}
is also called. A jump occurs. The preloader appears, disappears. And then appears. How to set the preloader to appear only on the request / api / v1 / todos / $ {todoId}
, not / api / v1 / todos /
.
axios.interceptors.request.use(function(config) {
if (config.url === `/api/v1/todos`) {
document.body.classList.add('preloader');
}
componentDidMOunt() {
this.todos();
}
todos = (idGroupTasks) => {
axios({
url: `/api/v1/todos`,
method: "GET"
})
.then(res => {
this.setState({
todos: res.data
});
this.todo(res.data[0].id)
})
.catch(error => {
console.log(error);
})
}
todo = (idTodo) => {
axios({
url: `/api/v1/todo/{idTodo}`,
method: "GET"
})
.then(res => {
this.setState({
todos: res.data
});
})
.catch(error => {
console.log(error);
})
}