Simple to-do app that lists my tasks and allows me to submit new ones. Connected to a REST API i built and so the tasks are retrieved using a call to that API. Im using useEffect to get all the tasks and store them in a tasks array. This should run every time the array changes (whhen i add a new task, when i delete a task, etc) so i dont have to refresh to see the changes.
useEffect code:
const [tasks, setTasks] = useState([])
useEffect(() => {
axios.get("http://localhost:8000/api/task-list")
.then(response => {
setTasks(response.data)
})
.catch(error => {
console.log(error)
})
}, [tasks])
Problem now is that theres near infinite calls to my API. It runs indefinitely and not only when the tasks array changes. I think this has something to do with it checking tasks === tasks and them not being the exact same like they seem. But Im not sure.
I'd really appreciate any help cuz I cant just continue like this while making infinite API calls. It only works now cuz the API is mine.