-
Notifications
You must be signed in to change notification settings - Fork 4
Example API Service File
Roy Lin edited this page Feb 4, 2022
·
2 revisions
This is an example of a service file, and how to call AsyncStorage APIs. Note that other files in the /onboarding
will then be able to call these functions by importing OnboardingService
and calling OnboardingService.PostInitialPeriodLength()
The purpose of this is so AsyncStorage API calls and parameter/return value validation are separate from our front-end code. Do not use AsyncStorage API calls in non-service files!
Please refer here for AsyncStorage docs for usage specifics: https://react-native-async-storage.github.io/async-storage/docs/usage/
import AsyncStorage from '@react-native-async-storage/async-storage';
const OnboardingService = {
// All APIs for Onboarding should be here
PostInitialPeriodLength: async function(periodLength) {
try {
const v = await AsyncStorage.setItem('periodLength', periodLength);
console.log(v);
return v;
} catch (e) {
// There was an error
}
}
};
export default OnboardingService;