-
-
Save dereknahman/a979100df8122a559ef29b1265039e3c to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import { Alert } from 'react-native'; | |
import AsyncStorage from '@react-native-community/async-storage'; | |
const STORAGE_KEY = '@has_stored_value'; | |
// TODO: add the readData in here | |
// it'll probably complain because we can only have one export default | |
// find out how/if i can export multiple functions and variables from many functions | |
//...in a single hook | |
//TODO: is the data = storedValue ok? Ask Alex later | |
export default () => { | |
const [errorMessage, setErrorMessage] = React.useState(''); | |
const saveData = async (data, callback) => { | |
try { | |
console.log(data, 'data!!'); | |
const storedData = await AsyncStorage.setItem(STORAGE_KEY, data); | |
storedData.then(() => { | |
console.log(storedData, 'testing'); | |
if (callback) { | |
callback(data); | |
} | |
console.log(data, 'DATAAA'); | |
return data; | |
}); | |
} catch (e) { | |
setErrorMessage('Language selection storage error'); | |
if (callback) { | |
callback(null); | |
} | |
return null; | |
} | |
}; | |
return [saveData, errorMessage]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment