uploadcare / react-file-uploader

MIT License
8 stars 0 forks source link

Set initial value for the uploader widget #46

Closed davibennun closed 1 month ago

davibennun commented 1 month ago

Set initial value for the uploader widget

Is there a way to set the initial value with any of the uploaders, more specifically, the Minimal one? If not, could anyone please direct me on how it can be done?

Thanks!

optlsnd commented 1 month ago

It can be set via the addFileFromUuid method (see Uploader API). Here's an example:

function App() {
  const uploaderRef = useRef<InstanceType<UploadCtxProvider> | null>(null);
  useEffect(() => {
    const api = uploaderRef.current?.getAPI();
    api?.addFileFromUuid(uuid, { // uuid – UUID of a file you want to pre-load
      silent: true,
    });
  }, []);

  return (
    <>
      <FileUploaderMinimal apiRef={uploaderRef} pubkey="demopublickey" />
    </>
  );
}