Skip to content

Commit

Permalink
Merge pull request #628 from yue4u/fix/rename-use-theme-key-and-updat…
Browse files Browse the repository at this point in the history
…e-type

fix: rename use theme key and update type
  • Loading branch information
yue4u authored Oct 9, 2024
2 parents 86530af + 6a7a273 commit dd69f2d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/styled/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ export function getThemeSync(key: string = LOCAL_STORAGE_KEY) {
*
* `dark` `light` という名前だけは特別扱いされていて、prefers-color-schemeにマッチした場合に返ります
*/
export const useTheme = (key: string = LOCAL_STORAGE_KEY) => {
assertKeyString(key)
export const useTheme = (localStorageKey: string = LOCAL_STORAGE_KEY) => {
assertKeyString(localStorageKey)
const isDark = useMedia('(prefers-color-scheme: dark)')
const media = isDark !== undefined ? (isDark ? 'dark' : 'light') : undefined
const [local, setTheme, ready] = useLocalStorage<string>(key)
const [local, setTheme, ready] =
useLocalStorage<typeof media>(localStorageKey)
const theme = !ready || media === undefined ? undefined : local ?? media
const system = local === undefined
return [theme, setTheme, system] as const
Expand Down

0 comments on commit dd69f2d

Please sign in to comment.