Last active
June 30, 2020 16:13
-
-
Save stevenselcuk/220eea4aa0a68c68d74957ee4036fe3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { Platform } from 'react-native'; | |
import { Appearance, useColorScheme } from 'react-native-appearance'; | |
import { useCallback, useEffect, useState } from 'react'; | |
export default function useThemeState(set) { | |
const [themeState, setThemeState] = useState(null); | |
useEffect(() => { | |
if (Platform.OS === 'web') { | |
setThemeState(colorScheme); | |
} else { | |
const subscription = Appearance.addChangeListener(({ colorScheme }) => { | |
setThemeState(colorScheme); | |
return () => subscription.remove(); | |
}); | |
} | |
}, []); | |
return themeState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment