score:2

Accepted answer

i believe you're not using the url prop from the props, so lemme remove it and add url to state instead.

export function fileupload({
  file,
  ondelete,
  onupload,
}: fileuploadprops) {
  const [progress, setprogress] = usestate(0);
  const [url, seturl] = usestate('');
  useeffect(() => {
    async function upload() {
      url = await uploadfile(file, setprogress);
      seturl(url) // this will set the state variable
      onupload(file, url);
    }
    upload();
  }, []);
  if (!url) { // checking for empty url here.
    return null;
  }

  return ( // this only gets returned when url is not empty
    <grid item>
      <fileheader file={file} url={url} ondelete={ondelete} />
      <linearprogress variant="determinate" value={progress} />
    </grid>
  );
}

Related Query

More Query from same tag