-
Notifications
You must be signed in to change notification settings - Fork 2
Example API Service File
Ramy Zhang edited this page Nov 12, 2022
·
2 revisions
This is an example of a service file, and how to call React-Native-FS APIs. Note that other files will then be able to call these functions by importing LessonPlanService
and calling LessonPlanService.setLessonPlanName()
The purpose of this is so React-Native-FS API calls and parameter/return value validation are separate from our front-end code. Do not use React-Native-FS API calls in non-service files!
Please refer here for React-Native-FS docs for usage specifics: https://github.com/itinance/react-native-fs
var RNFS = require('react-native-fs');
const LessonPlanService = {
// All APIs for LessonPlan should be here
setLessonPlanName: async function(value) {
try {
const v = await RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')
console.log(v);
return v;
} catch (e) {
// There was an error
}
},
...
};
export default LessonPlanService;