diff --git a/utils/_DATA.js b/utils/_DATA.js new file mode 100644 index 0000000..6778e0a --- /dev/null +++ b/utils/_DATA.js @@ -0,0 +1,38 @@ +import { AsyncStorage } from "react-native"; + +const dummyData = { + React: { + title: "React", + questions: [ + { + question: "What is React?", + answer: "A library for managing user interfaces" + }, + { + question: "Where do you make Ajax requests in React?", + answer: "The componentDidMount lifecycle event" + } + ] + }, + JavaScript: { + title: "JavaScript", + questions: [ + { + question: "What is a closure?", + answer: + "The combination of a function and the lexical environment within which that function was declared." + } + ] + } +}; + +export const STORAGE_KEY = "UdaciCard:StorageKey"; + +function setDummyData() { + AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(dummyData)); + return dummyData; +} + +export function fetchData(results) { + return results === null ? setDummyData() : JSON.parse(results); +}