@@ -14,131 +14,14 @@ An asynchronous, unencrypted, persistent, key-value storage system for React Nat
1414
1515## Getting Started  
1616
17+ Head over to [ documentation] ( https://react-native-community.github.io/async-storage/ )  to learn more.
1718
18- ### Install  
19- 
20- ``` 
21- $ yarn add @react-native-community/async-storage 
22- ``` 
23- 
24- ### Link  
25- 
26- -  ** React Native 0.60+** 
27- 
28- [ CLI autolink feature] ( https://github.com/react-native-community/cli/blob/master/docs/autolinking.md )  links the module while building the app. 
29- 
30- Use CocoaPods to add the native ` RNAsyncStorage `  to your project:
31- 
32- ``` bash 
33- $ npx pod-install
34- ``` 
35- 
36- -  ** React Native <= 0.59** 
37- 
38- 
39- ``` bash 
40- $ react-native link @react-native-community/async-storage
41- ``` 
42- 
43- * Note:*  For ` macOS `  and ` Windows `  the [ manual linking] ( docs/Linking.md )  is currently the only linking option.
44- 
45- 
46- See docs for [ manual linking guide.] ( docs/Linking.md ) 
47- 
48- ### ** Upgrading to React Native * 0.60+***    
49-  
50- React Native 0.60+ comes with ` autolinking `  feature, which automatically links Native Modules in your project.
51- In order to get it to work, make sure you ` unlink `  ` Async Storage `  first (if you had linked it before):
52- 
53- ``` bash 
54- $ react-native unlink @react-native-community/async-storage
55- ``` 
56- 
57- 
58- ## Usage  
59- 
60- AsyncStorage can only store ` string `  data, so in order to store object data you need to serialize it first. 
61- For data that can be serialized to JSON you can use ` JSON.stringify() `  when saving the data and ` JSON.parse() `  when loading the data.
62- 
63- 
64- ### Importing  
65- 
66- ``` js 
67- import  AsyncStorage  from  ' @react-native-community/async-storage'  ;
68- ``` 
69- 
70- ### Storing data  
71- 
72- ` setItem() `  is used both to add new data item (when no data for given key exists), and to modify exiting item (when previous data for given key exists).
73- 
74- #### Storing string value  
75- ``` jsx 
76- const  storeData  =  async  (value ) =>  {
77-   try  {
78-     await  AsyncStorage .setItem (' @storage_Key'  , value)
79-   } catch  (e) {
80-     //  saving error
81-   }
82- }
83- ``` 
84- 
85- #### Storing object value  
86- ``` jsx 
87- const  storeData  =  async  (value ) =>  {
88-   try  {
89-     const  jsonValue  =  JSON .stringify (value)
90-     await  AsyncStorage .setItem (' @storage_Key'  , jsonValue)
91-   } catch  (e) {
92-     //  saving error
93-   }
94- }
95- ``` 
96- 
97- ### Reading data  
98- 
99- ` getItem `  returns a promise that either resolves to stored value when data is found for given key, or returns ` null `  otherwise.  
100- 
101- #### Reading string value  
102- ``` jsx 
103- 
104- getData =  async  () =>  {
105-   try  {
106-     const  value  =  await  AsyncStorage .getItem (' @storage_Key'  )
107-     if (value !==  null ) {
108-       //  value previously stored
109-     }
110-   } catch (e) {
111-     //  error reading value
112-   }
113- }
114- 
115- ``` 
116- #### Reading object value   
117- 
118- ``` jsx 
119- 
120- getData =  async  () =>  {
121-   try  {
122-     const  jsonValue  =  await  AsyncStorage .getItem (' @storage_Key'  )
123-     return  jsonValue !=  null  ?  JSON .parse (jsonValue) :  null ;
124-   } catch (e) {
125-     //  error reading value
126-   }
127- }
128- 
129- ``` 
130- 
131- ## Advanced usage  
132- See docs for [ API and more examples] ( docs/API.md )  or [ advanced usages] ( docs/advanced ) .
133- 
134- ## Writing tests  
135- 
136- Using [ Jest] ( https://jestjs.io/ )  for testing? Make sure to check out [ docs on how to integrate it with this module.] ( ./docs/Jest-integration.md ) 
13719
13820## Contribution  
21+ Pull requests are welcome. Please open an issue first to discuss what you would like to change.
13922
140- See the [ CONTRIBUTING] ( CONTRIBUTING.md )  file for how to help out .
23+ See the [ CONTRIBUTING] ( CONTRIBUTING.md )  file for more information .
14124
14225## License  
14326
144- MIT
27+ MIT. 
0 commit comments