Skip to content

Commit d05ccdd

Browse files
author
Krzysztof Borowy
committed
docs: core docs
1 parent 6b1fa9e commit d05ccdd

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

packages/core/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.

0 commit comments

Comments
 (0)