1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-26 01:45:25 -04:00
jarv.is/hooks/useTheme.ts
2025-03-21 12:02:14 -04:00

16 lines
437 B
TypeScript

import { useContext } from "react";
import { ThemeContext } from "../contexts/ThemeContext";
// convenience hook to get access to ThemeContext's state/functions from pages/components/etc.
const useTheme = () => {
const context = useContext(ThemeContext);
if (!context) {
throw new Error("useTheme must be used inside of a ThemeProvider.");
}
return [context.theme, context.setTheme] as const;
};
export default useTheme;