i am kinda new to React Native and i am using expo, I am followint a course and during one lecture the teacher uses the package asyncstorage for cache topics. Everything worked fine the data was cached and I fetched the data without any issues. For some reason I wanted to go back how my app was before installing the package so I just commented out all the code that handles caching. I saved the file and the simulator doesn’t update it’s still fetching the data from the cache, I tried so many things like: resetting the chage, installing node again but nothing seems to work is like that file is protected or cached forever no matter what I do doesn’t reflect the changes in the simulator.
What drives me crazy is that if I add some console.log or new code those changes take effect but the data keeps coming from the cache.
here is the full code:
import { create } from 'apisauce';
import cache from '../utility/cache';
import AsyncStorage from '@react-native-async-storage/async-storage';
const apiClient = create({
baseURL: 'http://192.168.0.5:9000/api'
});
// const clearData = async () => {
// try {
// await AsyncStorage.clear();
// console.log('Cleared AsyncStorage');
// } catch (e) {
// console.error('Failed to clear AsyncStorage', e);
// }
// };
// clearData();
// Changing the implementation of a method
// const get = apiClient.get;
// apiClient.get = async (url, params, axiosConfig) => {
// // Before
// const response = await get(url, params, axiosConfig);
// console.log('response => ', response);
// if (response.ok) {
// cache.store(url, response.data);
// return response;
// }
// // After
// const data = await cache.get(url);
// return data ? { ok: true, data } : response;
// };
export default apiClient;
(all the commented code for the first time worked nicely, but then If I deleted them or just commented them in not working it’s like it is protected)
I do not know why is this happening, I was enjoying learning React Native but these things … are the worst part of the journey.
Here is the versions I am using:
"dependencies": {
"@react-native-async-storage/async-storage": "1.17.11",
"@react-native-community/masked-view": "^0.1.11",
"@react-native-community/netinfo": "9.3.7",
"@react-navigation/bottom-tabs": "^5.11.15",
"@react-navigation/native": "^5.9.8",
"@react-navigation/stack": "^5.14.9",
"apisauce": "^1.1.1",
"expo": "~48.0.18",
"expo-image-picker": "~14.1.1",
"expo-location": "~15.1.1",
"expo-status-bar": "~1.4.4",
"formik": "^2.1.4",
"lottie-react-native": "5.1.4",
"moment": "^2.29.4",
"react": "18.2.0",
"react-native": "0.71.8",
"react-native-gesture-handler": "~2.9.0",
"react-native-progress": "^4.1.2",
"react-native-reanimated": "~2.14.4",
"react-native-safe-area-context": "4.5.0",
"react-native-screens": "~3.20.0",
"yup": "^0.28.5"
},```
Like I said: deleting node again, cleaning the cache with all the commands that are out there for expo cli