I'm using useEffect and filling my state on the first render
const [data, setData ] = useState({});
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
fetchData();
}, [])
const fetchData = async () => {
setIsLoading(true)
await sanityAPI.fetch(
`url/ToGetData`
).then((res) => {
setData(res)
setIsLoading(false)
}).catch((err) => {
console.log(err)
});
}
when page is rendered the first time, if I console.log(data,'first time') in useEffect data, it gives me null
but after the first time if I go and just add another string in console.log(data,'second time'), and save it, the data shows, on the console.log.
Thanks a lot.