-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remix: fix loader data not updating (#4916)
* fix loader data not updating * rename store * dark mode hook * split components, drop useEffects
- Loading branch information
Showing
4 changed files
with
372 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
|
||
export function useIsDarkMode() { | ||
const [isDarkMode, setIsDarkMode] = React.useState<boolean>(false) | ||
|
||
React.useEffect(() => { | ||
const handleColorSchemeChange = (event: { | ||
matches: boolean | ((prevState: boolean) => boolean) | ||
}) => { | ||
setIsDarkMode(event.matches) | ||
} | ||
|
||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)') | ||
setIsDarkMode(mediaQuery.matches) | ||
mediaQuery.addListener(handleColorSchemeChange) | ||
|
||
return () => { | ||
mediaQuery.removeListener(handleColorSchemeChange) | ||
} | ||
}, []) | ||
|
||
return isDarkMode | ||
} |
Oops, something went wrong.