Example API Service File - uoftblueprint/the-period-purse GitHub Wiki

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/

OnboardingService.js

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;