APIUtilsoverlay.unmountAll

overlay.unmountAll

overlay.unmountAll is a function that completely removes all open overlays from both the React element tree and memory.

overlay.unmountAll();

Reference

overlay.unmountAll()

Call overlay.unmountAll when you need to free up memory for all overlays.

overlay.unmountAll();

Important Notes

  • When this function is called, overlays are immediately removed from memory, which may cause closing animations to not be displayed.
  • For overlays with animations, you should call overlay.closeAll first and then call overlay.unmountAll after the closing animations complete to provide a smooth user experience.

Interface

function unmountAll(): void;

Usage

Using Auto-generated IDs

Here’s a simple example of opening multiple overlays and removing them all using overlay.unmountAll.

overlay.open(({ isOpen, close, unmount }) => {
  return <ConfirmDialog isOpen={isOpen} close={close} onExit={unmount} />;
});
overlay.open(({ isOpen, close, unmount }) => {
  return <ConfirmDialog isOpen={isOpen} close={close} onExit={unmount} />;
});
overlay.open(({ isOpen, close, unmount }) => {
  return <ConfirmDialog isOpen={isOpen} close={close} onExit={unmount} />;
});
 
// Removes all three overlays above
overlay.unmountAll();

With Animations

For overlays with animations, you should call overlay.unmountAll after the closing animations complete to provide a natural user experience.

const overlayId = overlay.open(({ isOpen, close, unmount }) => {
  return <ConfirmDialog isOpen={isOpen} close={close} onExit={unmount} />;
});
 
overlay.closeAll();
 
setTimeout(() => {
  overlay.unmountAll();
}, 1000);