I am new to react so really sorry if this question has already been asked.
I am fetching data from an API in an useEffect hook and I only want to fetch it once but instead its being fetched twice for some reason.
Here's the code of useEffect hook
useEffect(() => {
    const fetchTasks = async () => {
      const res = await fetch('http://localhost:8080/tasks')
      const data = await res.json()
      console.log(data)
      for (let i = 0; i < data.length; i++) {
        setNewTaskContent(newTaskContent => [...newTaskContent, <Task task={data[i]} />])
      }
    }
    fetchTasks()
  }, [])
This was supposed to run once when the page was loaded but I am getting an array of data twice.
And if I am removing the dependency array from the hook, its fetching data continuously in a loop.
 
    