I try to recuperate a list from localStorage and set the table to the state like this:
const [favoritesExercices, setFavoritesExercices] = useState([]);
const retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('favoritesExercices');
if (value !== null) {
const ex =JSON.parse(value);
setFavoritesExercices([...favoritesExercices, ex]);
console.log(favoritesExercices);
}
} catch (e) {
console.error(e);
}
}
useEffect(() => {
retrieveData();
}, []);
With debugging I can see the array in the value variable but when I do console.log
to the store it is empty. Can anyone have an idea to fix this?