score:1

Accepted answer
const [ files, setFiles] = useState([]);
const filesRef = useRef(files);


const onFileAdded = fileURL => {
  setFiles([ ...files, fileURL ])
}

useEffect(() => {
  filesRef.current = files;
}, [files]);


useEffect(() => {
  return () => {
    filesRef.current.forEach(f => storageAPI.removeFile(f));
  }
}, []);

const onSave = () => {
  setFiles([]);
}

Related Query

More Query from same tag