MCPcopy Create free account
hub / github.com/denniskigen/react-weather / getInitialTheme

Function getInitialTheme

src/components/theme-context.jsx:4–17  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import PropTypes from 'prop-types';
3
4const getInitialTheme = () => {
5 if (typeof window !== 'undefined' && window.localStorage) {
6 const storedPrefs = window.localStorage.getItem('color-theme');
7 if (typeof storedPrefs === 'string') {
8 return storedPrefs;
9 }
10 const userMedia = window.matchMedia('(prefers-color-scheme: dark)');
11 if (userMedia?.matches) {
12 return 'dark';
13 }
14 }
15 // If you want to use dark theme as the default, return 'dark' instead
16 return 'light';
17};
18
19export const ThemeContext = React.createContext();
20

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected