import "server-only" import { cache } from "react" import { DEFAULT_THEME, type Theme } from "." const getRef = cache(() => ({ current: DEFAULT_THEME as Theme })) /** * Set the global theme * * It works kind of like React's context, * but on the server side, per request. * * @param newTheme */ export function setTheme(newTheme: Theme) { getRef().current = newTheme return newTheme } /** * Get the global theme * * Note: This must be called after setTheme() has been called in the page/layout. * If called before setTheme(), it will return DEFAULT_THEME. */ export function getTheme(): Theme { return getRef().current ?? DEFAULT_THEME }