@@ -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
1725Create 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";
2634const 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
4639After 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
6053await userStorage .setItem (" username" , " john_doe" );
6154
62- // read current value
55+
6356let username = await userStorage .getItem (" username" );
6457console .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
8577await userStorage .setMany ({
8678 email: " john@example.com" ,
8779 age: " 30" ,
8880});
8981
90- // read multiple items
9182const data = await userStorage .getMany ([" email" , " age" , " username" ]);
9283console .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
10191await userStorage .removeMany ([" email" , " age" , " not-here" ]);
10292```
0 commit comments