0
I’m trying to use useEffect
for a simple function, but error. It is not updating the page and saving the request I make with the function loadAll
in the useState
. When I load the page the result of storeInfo
is the null
which is the default value and not the updated value.
Give the dependency warning ( React Hook useEffect has a Missing dependency: 'storeInfo'. Either include it or remove the dependency array React-Hooks/exhaustive-deps )
const [storeInfo, setStoreInfo] = useState(null);
useEffect(()=>{
const loadAll = async () => {
let chosenInfo = await Tmdb.getStoreById(635302);
setStoreInfo(chosenInfo);
}
console.log(storeInfo)
loadAll();
}, []);
If I put storeInfo
in the request dependency array gets infinite loop.
const [storeInfo, setStoreInfo] = useState(null);
useEffect(()=>{
const loadAll = async () => {
let chosenInfo = await Tmdb.getStoreById(635302);
setStoreInfo(chosenInfo);
}
console.log(storeInfo)
loadAll();
}, [storeInfo]);
I don’t know what else to do :( If anyone can help me, I’d be grateful!