I’m trying to get item from local storage but its not rendering with me correctly, which I should refresh the app by making any change in the code and save whenever I log in or logout here is my code
useEffect(() => {
const _getUserhData = async () => {
try {
let userInfo = await AsyncStorage.getItem('userData');
if (userInfo) {
const parsedUserData = JSON.parse(userInfo);
setUserData(parsedUserData);
console.log(userData, 'userData');
}
} catch (error) {
console.error('Error retrieving data:', error);
}
};
_getUserhData();
}, [userInfo]);
2
Answers
From what you have shared there is no
userInfo
declared in scope, e.g. the scope of the React function component body.From what I can tell of your code you should just remove
userInfo
and use an empty dependency array since there are no external dependencies in theuseEffect
hook callback.Use this when user opens the screen