the problem: that user will upload image and the
code will return the download url
set the state in the url
store the url in the local storage the code that doing the following is : import {
getDownloadURL,
ref,
uploadBytesResumable,
UploadTask,
} from 'firebase/storage';
import { IState } from '../store/state';
import { storage } from '../../firebase';
const getDownload = async (uploadTask: UploadTask, state: IState) => {
const downloadUrl = getDownloadURL(uploadTask.snapshot.ref).then(
(downloadURL) => {
console.log('File available at', downloadURL);
localStorage.setItem('logoUrl', downloadURL);
return downloadURL;
}
);
return downloadUrl;
};
export const uploadLogo = async (file: any, state: IState) => {
//
if (!file) return;
const sotrageRef = ref(storage, `files/${file.name}`);
const uploadTask = uploadBytesResumable(sotrageRef, file);
return uploadTask.on(
'state_changed',
(snapshot: { bytesTransferred: number; totalBytes: number }) => {
const prog = Math.round(
(snapshot.bytesTransferred / snapshot.totalBytes) * 100
);
},
(error: any) => console.log(error),
async () => {
state.logoUrl = await getDownload(uploadTask, state);
}
);
};
the user press on button to upload his image then the local storage is updated with the new URL but the state isn't
ps: i am using Overmind to manage my state