I am trying to fetch data from an api , however I am using `` (template literals) instead of "" to modify the link. the modifications take value from a state that I have declared before.
const [data,setData] = React.useState([])
const [date,setDate] =React.useSatate([])
const URL= `https://api.blablabla/${date[2]}`
then I want to use useEffect to set the received data to state [data]
useEffect(()=>{
fetch(URL)
.then(res=>res.json())
.then(data=>setData(data))
},[])
the console shows :
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.
If I use the link with "" like
const URL = "https://api.blablabla/date"
it seems to work fine but then I will not be able to use interpolation to modify the request link
How do I properly execute this so I can send Modified API requests that takes in value from a previously defined state? What is an efficient way to do so?