MCPcopy Create free account
hub / github.com/dabbott/react-native-express / App

Function App

examples/files/app/AsyncStorage.js:9–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7const STORAGE_KEY = 'ASYNC_STORAGE_NAME_EXAMPLE'
8
9export default function App() {
10 const [name, setName] = useState('World')
11
12 async function loadName() {
13 try {
14 const name = await AsyncStorage.getItem(STORAGE_KEY)
15
16 if (name === null) return
17
18 setName(name)
19 } catch (e) {
20 console.error('Failed to load name.')
21 }
22 }
23
24 async function saveName(name) {
25 try {
26 await AsyncStorage.setItem(STORAGE_KEY, name)
27 setName(name)
28 } catch (e) {
29 console.error('Failed to save name.')
30 }
31 }
32
33 useEffect(() => {
34 loadName()
35 }, [])
36
37 return (
38 <View>
39 <Input
40 placeholder={'Type your name, hit enter, and refresh!'}
41 onSubmitEditing={(value) => {
42 saveName(value)
43 }}
44 />
45 <Text style={styles.text}>Hello {name}!</Text>
46 </View>
47 )
48}
49
50const styles = StyleSheet.create({
51 text: {

Callers

nothing calls this directly

Calls 1

loadNameFunction · 0.85

Tested by

no test coverage detected