Cómo almacenar imágenes en caché en React Native
Nov 29 2022
Te mostraré guardar imágenes en caché. Usaremos esta biblioteca para guardar la imagen: react-native-fs.

Te mostraré guardar imágenes en caché. Usaremos esta biblioteca para guardar la imagen: react-native-fs .
Para comenzar a usar el flujo de archivos, primero importe react-native-fs :
import RNFS from 'react-native-fs';
let CacheDir = RNFS.CachesDirectoryPath + '/';
{"bytesWritten": 0, "jobId": 1, "statusCode": 200}
function saveImageInCache(imageUrl, imageName) {
let filePath = CacheDir + imageName;
RNFS.downloadFile({
fromUrl: imageUrl,
toFile: filePath,
}).promise.then(response => {
if(response.statusCode == 200)
return filePath;
})
}
async function isExistImage(imagePath) {
await RNFS.exists(imagePath)
.then((exists) => {
return exists;
});
}