Answer the question
In order to leave comments, you need to log in
React throws an error when adding a task?
index.js:1 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
const getUser = () => {
axios.get('http://localhost:3001/users').then(({ data }) => {
data.map(data => {
if(data.authorized){
setStatus(data.authorized);
setUser(data);
}
return data;
});
});
}
const updateList = () => {
axios.get('http://localhost:3001/lists?_expand=color&_embed=tasks').then(({ data }) => {
if(user){
const lists = data.filter(l => l.userId === user.id);
setLists(lists);
}
});
}
useEffect (() => {
axios.get('http://localhost:3001/colors').then(({ data }) => {
setColor(data);
});
getUser();
}, [status, history.location.pathname])
useEffect(() => {
if(Array.isArray(colors)){
selectColor(colors[0].id);
}
updateList();
}, [colors, user])
useEffect(() => {
const listId = history.location.pathname.split('lists/')[1];
if (lists.length > 1) {
const list = lists.find(list => list.id === Number(listId));
setActiveItem(list);
}
}, [lists, history.location.pathname])
const addTask = () => {
const obj = {
"listId": list.id,
"text": inputValue,
"completed": false,
"id": Math.random()
};
axios.post('http://localhost:3001/tasks', obj).then(({ data }) => {
onAddTask(list.id, obj);
setShowForm(false);
})
.catch(e => {
alert('Ошибка при добавлении задачи!');
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question