Skip to main content
react-md

useHtmlClassName

function useHtmlClassName(className: string): void;

This hook can be used to dynamically apply a single className to the document.documentElement (<html>) using the classList API.

Example Usage

A great use-case for this hook is to apply a dark-mode or light-mode class based on the user's preference.

function Example() {
  const { currentColor } = useColorScheme();
  useHtmlClassName(`${currentColor}-mode`);
  return null;
}

Parameters

Returns

Nothing.

See Also