**local data and then sync**
=
> import {AsyncStorage} from 'react-native';
Persisting data:
<!-- language: lang-js -->
_storeData = async () => {
try {
await AsyncStorage.setItem('@MySuperStore:key', 'I like to save it.');
} catch (error) {
// Error saving data
}
};
<!-- end snippet -->
Fetching data:
<!-- language: lang-js -->
_retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('TASKS');
if (value !== null) {
// We have data!!
console.log(value);
}
} catch (error) {
// Error retrieving data
}
};
<!-- end snippet -->
I believe what you meant is to pass a value from one screen to another.
You can either use [AsyncStorage][1] to keep the data inside your memory, or pass the data through props [navigation][2]
AsyncStorage example:
Store Data:
_storeData = async () => {
try {
await AsyncStorage.setItem('@MySuperStore:key', 'I like to save it.');
} catch (error) {
// Error saving data
}
}
Fetch Data:
_retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('TASKS');
if (value !== null) {
// We have data!!
console.log(value);
}
} catch (error) {
// Error retrieving data
}
}
Passing data through props navigation:
First class:
<Button onPress = {
() => navigate("ScreenName", {name:'Jane'})
} />
Second class:
const {params} = this.props.navigation.state
[1]: https://facebook.github.io/react-native/docs/asyncstorage
[2]: https://stackoverflow.com/a/47858644/8645857