I am using react-native-fs to list and delete files in my app, I have listed all the files in one component and I have another component to show the file(Image Viewer), I want to delete the file on Image viewer and should redirect to list page after deleting a file, Deleting a file I am navigating to List component, but still I can see the deleted file on the list
deleteImageFile = () => {
const fileName = this.state.fileName;
const dirPicutures = RNFS.DocumentDirectoryPath;
const filepath = `${dirPicutures}/${fileName}`;
RNFS.exists(filepath)
.then( (result) => {
console.warn("file exists: ", result);
if(result){
return RNFS.unlink(filepath)
.then(() => {
console.warn('FILE DELETED');
this.props.navigation.navigate('Gallery');
})
// `unlink` will throw an error, if the item to unlink does not exist
.catch((err) => {
console.warn(err.message);
});
}
})
.catch((err) => {
console.warn(err.message);
});
}
If there is file existing in the directory then File is deleting and if not I am getting file not exist message.
After successful deleting I am calling
this.props.navigation.navigate('Gallery');
Gallery is main screen(List screen), the redirect also working but the deleted file is still present in the list.
Please help me on this.