I try to call two functions in my useEffect hook
import React, { useState, useEffect } from "react";
export const LocalWeather = () => {
const APP_KEY = "XXX";
const [userPlace, setUserPlace] = useState([]);
const [localWeather, setLocalWeather] = useState([]);
async function getUserData() {
await fetch("http://ip-api.com/json")
.then((res) => res.json())
.then((data) => {
setUserPlace({
country: data.country,
city: data.city,
});
console.log(data);
})
.catch((err) => console.log(err));
}
async function getLocalWeather() {
await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${userPlace.city}&appid=${APP_KEY}`
)
.then((res) => res.json())
.then((data) => {
setLocalWeather({
temperature: Math.round(data.main.temp - 273.15),
});
})
.catch((err) => console.log(err));
}
useEffect(() => {
getUserData();
getLocalWeather();
});
return (
<div>
<h3>
Your current place is: {userPlace.country}, {userPlace.city}
</h3>
{localWeather.temperature ? (
<h4>Temperature in your city is: {localWeather.temperature} ℃</h4>
) : null}
</div>
);
};
When I try to add [] to my use useEffect eslint automatically changes it into:
useEffect(() => {
getUserData();
getLocalWeather();
}, [getLocalWeather]);
What should I do to be able to call my both functions only on the first render?
Thank you for your help!