Overview
useDocumentTheme provides the current document theme reactively. It watches document.documentElement for changes to the data-theme attribute or class using a MutationObserver, and re-renders your component when the theme changes.
Signature
Returns
The current document theme.
Usage
How It Works
The hook usesMutationObserver to watch for:
- Changes to
data-themeattribute (set byapplyDocumentTheme) - Changes to
classattribute (Tailwind CSSdarkclass convention)