Could you please assist me in identifying my mistake here? I saw it being done in a video.
The error message I am encountering is:
TypeError: undefined is not an object (evaluating 'media.cancelled')
const [isUploading, setIsUploading] = useState(false);
const [isPaused, setIsPaused] = useState(false);
const [downloadUrl, setDownloadUrl] = useState();
const [uploadTask, setUploadTask] = useState();
const [uploadTaskSnapshot, setUploadTaskSnapshot] = useState({});
const onTakePhoto = () => {
launchCamera({ mediaType: 'photo', saveToPhotos:true }, onMediaSelect())
};
const onSelectImagePress = () => {
launchImageLibrary({ mediaType: 'photo', saveToPhotos:true }, onMediaSelect())
};
const onMediaSelect = async media => {
if (!media.didCancel) {
setIsUploading(true);
const ref = storage().ref(media.assets[0].fileName);
const task = ref.putFile(media.assets[0].uri);
setUploadTask(task);
task.on('state_changed', taskSnapshot => {
setUploadTaskSnapshot(taskSnapshot);
});
task.then(async () => {
const downloadURL = await ref.getDownloadURL();
setDownloadUrl(downloadURL);
alert(downloadUrl)
setIsUploading(false);
setUploadTaskSnapshot({});
})
}
};