Theme

initTheme

Apply stored theme class before React paints — optional guard for flash-of-incorrect-theme.

initTheme()

Reads localStorage['manic-theme'] and applies the same dark class logic as ThemeProviderwindow only.

import { initTheme } from 'manicjs/theme';

initTheme();

When it runs today

packages/manic/src/theme/index.ts automatically calls initTheme() on module load in the browser:

if (typeof window !== 'undefined') {
  initTheme();
}

Importing ThemeProvider from manicjs/theme (or manicjs) executes this side effect. You rarely call initTheme() manually unless you split bundles and need an earlier inline script.


SSR / Bun

Function returns immediately when window is undefined — safe but no-op during SSR.


Imports

import { initTheme } from 'manicjs/theme';

(manicjs root barrel does not re-export initTheme — use manicjs/theme.)


See also

On this page