Importing the AsyncStorage library:
import { AsyncStorage } from 'react-native';
Persisting data:
_storeData = async () => {
try {
await AsyncStorage.setItem(
'@MySuperStore:key',
'I like to save it.'
);
} catch (error) {
// Error saving data
}
};
Fetching data:
_retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('TASKS');
if (value !== null) {
// We have data!!
console.log(value);
}
} catch (error) {
// Error retrieving data
}
};
JSON.stringify(value)
JSON.parse(jsonValue)
clearAll = async () => {
try {
await AsyncStorage.clear()
} catch(e) {
// clear error
}
console.log('Done.')
}
nodejs.channel.addListener(
"GetMyDocsNew",
(msg) => {
alert("From node GetMyDocsNew : " + JSON.stringify(msg))
this.StoringData('@GetMyDocsNew', JSON.stringify(msg));
},
this
);