useInert

Applies inert to entire DOM-tree, excluding ref and its descendants.

  • @param when - Whether to apply the inert attribute.
  • @param ref - The element to exclude from the inert attribute.
  • @returns void

Example

const [isDialogOpen, setIsDialogOpen] = useState(false)
const dialogRef = useRef<HTMLElement>(null)
 
useInert(isDialogOpen, dialogRef)
 
return (
  <Dialog ref={dialogRef} open={isDialogOpen} onClose={setIsDialogOpen} />
)