I have this typescript code where I want to do something as you can see inside the second useEffect hook with the user variable in it. But my question is if I don’t get the logged in user do the code in the second useEffect hook does it run?? If not, how could I run this code when user if not logged in but only after I check if user if logged in or not?? Thank you.
const [user, setUser] = useState<UserProps>();
const [likedRecipes, setLikedRecipes] = useState();
const [viewedRecipes, setViewedRecipes] = useState();
useEffect(() => {
getLoggedInUser().then((user) => {
setUser(user);
});
}, []);
useEffect(() => {
if (!user && cookies().has("likedRecipes")) {
getCookie("likedRecipes").then((recipes) => {
setLikedRecipes(JSON.parse(recipes!.value));
});
}
if (!user && cookies().has("viewedRecipes")) {
getCookie("viewedRecipes").then((recipes) => {
setViewedRecipes(JSON.parse(recipes!.value));
});
}
}, [user]);
New contributor
sujal.suhaas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2