Skip to content

Instantly share code, notes, and snippets.

@Yoncity
Created May 23, 2021 21:21
Show Gist options
  • Save Yoncity/d828386833766788d226d886ea0bc9b9 to your computer and use it in GitHub Desktop.
Save Yoncity/d828386833766788d226d886ea0bc9b9 to your computer and use it in GitHub Desktop.
import {useContext} from 'react';
import {ThemeContext} from '../components/ThemeManager';
import * as AsyncStorage from '../components/AsyncStorage';
export default props => {
const {theme, toggleTheme} = useContext(ThemeContext);
const readTheme = async () => {
const data = await AsyncStorage.retrieveData('SETTINGS_KEY');
if (data !== null && data !== undefined) {
toggleTheme(data);
}
};
const updateTheme = async value => {
await AsyncStorage.storeData('SETTINGS_KEY', value);
toggleTheme(value);
};
return [theme, readTheme, updateTheme];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment