How To Cache Image In React Native

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;
});
}

--

--

React Native Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store