File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ # Async Storage Core
2+
3+ Main Async Storage component.
4+
5+ ## Installation
6+
7+ ``` bash
8+ $ yarn install @react-native-community/async-storage
9+ ```
10+
11+ ## Usage
12+
13+ Use ` AsyncStorageFactory ` to create your Async Storage instance
14+
15+
16+ ``` typescript
17+
18+ // storage.js
19+
20+ import ASFactory from ' @react-native-community/async-storage'
21+
22+ // use any available Storage Backend
23+ const storageBackend = new StorageBackend ();
24+
25+ const mobileStorage = ASFactory .create (storageBackend );
26+
27+ export default mobileStorage ;
28+ ```
29+
30+ ## Providing a storage model
31+
32+ You can provide a ` Model ` type when creating Async Storage, to have a fully typed storage.
33+
34+
35+ ``` typescript
36+ import ASFactory from ' @react-native-community/async-storage'
37+
38+ type StorageModel = {
39+ user: {
40+ name: string ;
41+ age: number ;
42+ };
43+ preferences: {
44+ darkModeEnabled: boolean ;
45+ };
46+ subscribedChannels: Array <Channel >;
47+ onboardingCompleted: boolean ;
48+ };
49+
50+ // use any available Storage Backend
51+ const storageBackend = new StorageBackend ();
52+
53+ const storage = ASFactory .create <StorageModel >(storageBackend );
54+
55+ ```
56+
57+ ## License
58+
59+ MIT.
You can’t perform that action at this time.
0 commit comments