I want to update the time every minute without refreshing the whole page.
This is a part from the code which I used from github:
const fetchData = async () => {
setIsLoading(true);
try {
const forecastResponse = await axios.get(endpoint, { params });
const payload = mapData(
forecastResponse.data.daily,
forecastResponse.data.current,
lang,
);
dispatch({
type: SUCCESS,
payload,
});
} catch (error) {
console.error(error.message);
dispatch({ type: FAILURE, payload: error.message || error });
}
setIsLoading(false);
};
useEffect(() => {
fetchData();
const interval = setInterval (() => {
fetchData()
}, 60000)
return() => clearInterval(interval)
}, [lon, lat]);
return { data, isLoading, errorMessage, fetchData };
};
I tried to solve the problem by adding
"const interval = setInterval (() => {
fetchData()
}, 60000)"
in useEffect
but website still does a refresh. How can I do it with the corret way that only the time, every minute, changes?