I was working with an api meaning that I fetch the api and convert it to json before i pass it to one of the state i want to update.
It was working fine until it didn't.
const [ids, setIDs] = useState([]);
This is the code for fetching from the api
const fetchData = async () => {
//setting up the video ids
const res = await fetch("http://localhost:3000/videosid");
const jsonRes = await res.json();
setIDs(jsonRes);
//setting up the local database
console.log("Fetching data from youtube...");
console.log("ids:", ids);
localStorage.setItem("VideosID", ids);
};
when I console.log the values of res and jsonRes everything shows up, but for some reason it does not update the state.
Any ideas why ?
EDIT
I would also like to say that when doing the same with a local json file the state updates immediately.
const localfetchData = () => {
//setting up the video ids
setIDs(jsonfile);
//setting up the local database
localStorage.setItem("VideosID", ids);
};