Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const CldUploadWidget = ({
}: CldUploadWidgetProps) => {
const cloudinary: CldUploadWidgetCloudinaryInstance = useRef();
const widget: CldUploadWidgetWidgetInstance = useRef();
const isMounted = useRef<boolean>();

const [error, setError] = useState<CloudinaryUploadWidgetError | undefined>(undefined);
const [results, setResults] = useState<CloudinaryUploadWidgetResults | undefined>(undefined);
Expand Down Expand Up @@ -116,6 +117,10 @@ const CldUploadWidget = ({
*/

function handleOnLoad() {
if (!isMounted.current) {
return;
}

setIsScriptLoading(false);

if ( !cloudinary.current ) {
Expand All @@ -132,8 +137,13 @@ const CldUploadWidget = ({
});
}

useEffect(() => {
isMounted.current = true;
},[])

useEffect(() => {
return () => {
isMounted.current = false;
widget.current?.destroy();
widget.current = undefined;
}
Expand Down Expand Up @@ -248,4 +258,4 @@ const CldUploadWidget = ({
);
};

export default CldUploadWidget;
export default CldUploadWidget;