Skip to content

Commit 55de8bd

Browse files
committed
docs: improve
1 parent f100276 commit 55de8bd

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,11 @@ import { createAsyncStorage } from "@react-native-async-storage/async-storage";
7979
const storage = createAsyncStorage("appDB");
8080

8181
async function demo() {
82-
// save value under "userToken" key
8382
await storage.setItem("userToken", "abc123");
84-
85-
// read value stored at "userToken" key
83+
8684
const token = await storage.getItem("userToken");
8785
console.log("Stored token:", token); // abc123
88-
89-
// remove value from storage
86+
9087
await storage.removeItem("userToken");
9188
}
9289
```

docs/api/usage.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ It mirrors the Web Storage API, with additional support for batch operations.
1212
**Note:** AsyncStorage only stores strings. To save objects, arrays, or other non-string values, serialize them with
1313
`JSON.stringify` before storing, and use `JSON.parse` when reading them back.
1414

15+
## Scoped storage
16+
17+
Each storage instance has its own isolated data, independent of other instances, based on the name you give it. This is known as **scoped storage**.
18+
19+
!!! warning "Windows and visionOS support"
20+
21+
Windows and visionOS do not support scoped storages. It falls back to the previous v2 implementation, which provides a single storage per application.
22+
1523
## Creating a storage
1624

1725
Create a new storage instance by calling `createAsyncStorage` with a unique database name:
@@ -26,21 +34,6 @@ import { createAsyncStorage } from "@react-native-async-storage/async-storage";
2634
const userStorage = createAsyncStorage("john");
2735
```
2836

29-
Each instance is uniquely identified by its name.
30-
Data in one storage instance is isolated, ensuring that different names do not share data.
31-
32-
!!! note "Web"
33-
34-
On the Web, AsyncStorage uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API), which supports scoped storages.
35-
36-
!!! warning "Windows"
37-
38-
Windows does not support scoped storages. It falls back to the previous v2 implementation, which provides a single storage per application.
39-
40-
!!! warning "visionOS"
41-
42-
visionOS does not support scoped storages. It falls back to the previous v2 implementation, which provides a single storage per application.
43-
4437
## Using a storage
4538

4639
After creating a storage instance, the storage is ready to use.
@@ -59,7 +52,7 @@ await userStorage.setItem("username", "doe_john");
5952
// previously stored value is overriden
6053
await userStorage.setItem("username", "john_doe");
6154

62-
// read current value
55+
6356
let username = await userStorage.getItem("username");
6457
console.log(username); // "john_doe"
6558

@@ -81,13 +74,11 @@ applied, or none if an error occurs.
8174
- `removeMany` deletes multiple keys; non-existing keys are ignored without errors.
8275

8376
```typescript
84-
// store values
8577
await userStorage.setMany({
8678
email: "john@example.com",
8779
age: "30",
8880
});
8981

90-
// read multiple items
9182
const data = await userStorage.getMany(["email", "age", "username"]);
9283
console.log(data);
9384
// {
@@ -96,7 +87,6 @@ console.log(data);
9687
// username: null, // key doesn't exist
9788
// }
9889

99-
// remove multiple items
10090
// non-existing keys are ignored
10191
await userStorage.removeMany(["email", "age", "not-here"]);
10292
```

0 commit comments

Comments
 (0)