how do i get these providers?
so i was following the javascript mastery tutorial and i did the exact same thing , but this useEffect to get the providers isnt working ( i tried alerting it to see it keeps showing null)
here’s the piece of code of the providers , tell me what could be wrong
const [providers, setProviders] = useState(null);
const [toggleDropdown, setToggleDropdown] = useState(false);
useEffect(() => {
const setUpProviders = async () => {
const response = await getProviders();
setProviders(response);
};
setUpProviders();
}, []);
2
Answers
here is the full code :
This is expected behaviour of
useState
hook. You can useuseEffect
to check when your variable updates.For detailed explanation of this behaviour, check this