I'm building a webapp with react and i get this warning:
src\Containers\App.js
Line 30:6: React Hook useEffect has a missing dependency: 'API_KEY'. Either include it or remove the dependency array react-hooks/exhaustive-deps
Line 36:6: React Hook useEffect has a missing dependency: 'API_KEY'. Either include it or remove the dependency array react-hooks/exhaustive-deps
Here the App.js code:
import React, { useState, useEffect } from 'react';
import './App.css';
import 'tachyons';
const App = () => {
const API_KEY = `...`;
const [searchField, setSearchField] = useState('');
const [countryField, setCountryField] = useState('');
const [currentData, setCurrentData] = useState(null);
const [oneCallData, setOneCallData] = useState(null);
useEffect(() => {
fetch(`https://api.openweathermap.org/data/2.5/weather?q=Cinisi&units=metric&appid=${API_KEY}`)
.then(resp => resp.json())
.then(dataRecived => {
setCurrentData(dataRecived);
})
}, []);
useEffect(() => {
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=38.1562&lon=13.1073&units=metric&exclude=current,minutely,alerts&appid=${API_KEY}`)
.then(resp => resp.json())
.then(dataRecived => setOneCallData(dataRecived))
}, []);
...
thank in advance anyone who tries to give me an answer