Is it correct that a useEffect is listening to the context?
const {
data,
} = useContext(AuthContext);
async function getProfile() {
try {
setLoading(true);
console.info('getProfile called', data.token);
const response = await getByToken(data.token);
if (response && response.ok) {
setFirstName(response.userData.firstName);
setLastName(response.userData.lastName);
setEmail(response.userData.email);
}
} catch (e) {
console.info('Error', e);
} finally {
setLoading(false);
}
}
useEffect(() => {
if (data.userData) {
getProfile();
}
}, [data.userData]);
This is the way I found to make it make calls to getProfile with a userData different from null