-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path62_async_storage.js
90 lines (71 loc) · 1.63 KB
/
62_async_storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React,{useEffect,useState,useRef} from 'react';
import {Platform,Button, TextInput,Text,StatusBar, View,ActivityIndicator,StyleSheet,Modal,Pressable,ScrollView,FlatList } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const App = () => {
const [name,setName] = useState('')
const setData = async ()=>{
try{
await AsyncStorage.setItem('name','ankur singh')
}catch(e){
console.warn(e);
}
}
const getData = async ()=>{
try{
const value = await AsyncStorage.getItem('name');
setName(value);
console.warn(value);
}
catch(e){
console.warn(e);
}
}
const removeData = async ()=>{
try{
await AsyncStorage.removeItem('name');
}
catch(e){
console.warn(e);
}
}
return (
<View style={styles.container}>
<Text>Async Storage with React Native | {name}</Text>
<Button title='Set data' onPress={setData} />
<Button title='Get data' onPress={getData}/>
<Button title='Remove data' onPress={removeData}/>
</View>
)
};
const styles=StyleSheet.create({
container:{
flex:1,
},
dataWrapper:{
flexDirection:'row',
justifyContent:'space-around',
backgroundColor:'lightgrey',
margin:10,
padding:5
},
centredView:{
flex:1,
justifyContent:'center',
alignItems:'center',
},
modalView:{
margin:20,
backgroundColor:"#fff",
padding:20,
borderRadius:10,
shadowColor:'#000',
shadowOpacity:0.75,
elevation:5,
},
input:{
borderWidth:1,
borderColor:'skyblue',
marginBottom:10,
}
})
export default App;