Skip to content

Instantly share code, notes, and snippets.

@stevenselcuk
Last active June 30, 2020 16:13
Show Gist options
  • Save stevenselcuk/220eea4aa0a68c68d74957ee4036fe3f to your computer and use it in GitHub Desktop.
Save stevenselcuk/220eea4aa0a68c68d74957ee4036fe3f to your computer and use it in GitHub Desktop.
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