useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data[0]))
.catch(err => console.warn(err))
}, [cityKey])
How do I solve this warning?
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data[0]))
.catch(err => console.warn(err))
}, [cityKey])
How do I solve this warning?
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data[0]))
.catch(err => console.warn(err))
}, [cityKey,url])
As per the warning suggested solution, include url in the dependency array.
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data[0]))
.catch(err => console.warn(err))
}, [cityKey, url])
Alternatively, you might disable the warning (but not recommended):
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data[0]))
.catch(err => console.warn(err))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cityKey])