Skip to content

Instantly share code, notes, and snippets.

@stevenselcuk
Created June 30, 2020 16:06
Show Gist options
  • Select an option

  • Save stevenselcuk/488fb3a0940aae042e325554bbaa587f to your computer and use it in GitHub Desktop.

Select an option

Save stevenselcuk/488fb3a0940aae042e325554bbaa587f to your computer and use it in GitHub Desktop.
Get / Dedect Appereance (Dark Mode) for old React Native versions
import {Appearance, useColorScheme} from 'react-native-appearance';
import {useCallback, useEffect, useState} from 'react';
export default function useThemeState() {
const [themeState, setThemeState] = useState(null);
useEffect(() => {
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