You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/brownfield.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
!!! info
2
2
3
-
Brownfield integration is supported on **Android**, **iOS** and **macOS**.
3
+
Brownfield integration is supported on **Android**, **iOS**, and **macOS**.
4
4
5
-
`AsyncStorage` is built on a shared storage layer (`SharedStorage`) that can also be accessed directly from native code.
6
-
This is useful in brownfield scenarios, where your app combines React Native and native code, and you want both layers to read/write from the same storage consistently.
5
+
`AsyncStorage` is built on a shared storage layer (`SharedStorage`) that can also be accessed directly from native
6
+
code.
7
+
This is especially useful in brownfield scenarios, where your app combines React Native and native code, allowing both
8
+
layers to read from and write to the same storage consistently.
7
9
8
10
All platforms provide a thread-safe singleton registry called `StorageRegistry` to manage storage instances.
9
11
10
12
### Android
11
13
12
-
On Android, `StorageRegistry` is public singleton, which is used to share `SharedStorage` instances with Native module.
14
+
On Android, `StorageRegistry` is a public singleton, which is used to share `SharedStorage` instances with the native module.
13
15
Multiple calls with the same name return the same singleton instance, ensuring consistent access.
14
16
15
17
```kotlin
@@ -30,7 +32,7 @@ runBlocking {
30
32
31
33
### iOS / macOS
32
34
33
-
On iOS/macOS, the `StorageRegistry` singleton provides the same functionality in Swift/Objc.
35
+
On iOS and macOS, the `StorageRegistry` singleton provides the same functionality in Swift and Objective-C.
Copy file name to clipboardExpand all lines: docs/api/db-naming.md
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,14 @@
1
1
## How `databaseName` is used
2
2
3
-
When creating a new storage instance with `createAsyncStorage(databaseName)`, the provided `databaseName` determines where and how the underlying database file is stored on each platform.
4
-
This ensures that storages are scoped by name and do not leak data between one another.
3
+
When creating a new storage instance with `createAsyncStorage(databaseName)`, the provided `databaseName` determines the
4
+
location and structure of the underlying database file on each platform.
5
+
This ensures that each storage instance is scoped by name and prevents data from leaking between instances.
5
6
6
7
### iOS & macOS
7
8
8
-
On Apple platforms, the storage is located under the app’s `Application Support` directory.
9
-
The `databaseName` is normalized into a file path with the `.sqlite` extension.
10
-
Each `databaseName` creates its own subdirectory inside `async-storage/databases`.
9
+
On Apple platforms, storage is located in the app’s `Application Support` directory.
10
+
The `databaseName` is normalized into a file path with the `.sqlite` extension, and each `databaseName` creates its own
Copy file name to clipboardExpand all lines: docs/api/usage.md
+26-18Lines changed: 26 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,48 +4,51 @@ title: Usage
4
4
5
5
# Using Async Storage
6
6
7
-
The [`AsyncStorage`](https://github.com/react-native-async-storage/async-storage/blob/main/packages/async-storage/src/AsyncStorage.ts) interface provides an asynchronous, promise-based API for persistent key-value storage.
8
-
Each method is modeled after the Web Storage API, with extensions for batch operations.
interface provides a promise-based API for persistent key-value storage.
10
+
It mirrors the Web Storage API, with additional support for batch operations.
9
11
10
-
Similar to Web, AsyncStorage deals with data that should be already serialized (strings). If you need to store objects, arrays, or other non-string values, you must serialize them first (for example, using `JSON.stringify`) and deserialize them when retrieving (for example, using `JSON.parse`).
12
+
**Note:** AsyncStorage only stores strings. To save objects, arrays, or other non-string values, serialize them with
13
+
`JSON.stringify` before storing, and use `JSON.parse` when reading them back.
11
14
12
15
## Creating a storage
13
16
14
-
To create a new storage, call `createAsyncStorage` with your database name:
17
+
Create a new storage instance by calling `createAsyncStorage` with a unique database name:
15
18
16
-
!!! note "About naming"
19
+
!!! note "Naming"
17
20
18
-
It's best to avoid adding an extensions to the name. Read more at [Database naming](db-naming.md) section.
21
+
Avoid including file extensions in the database name (like "user.db"). See [Database naming](db-naming.md) for details.
This returns an instance of `AsyncStorage` and each instance is uniquely identified by the name you provide.
27
-
The data in one storage instance is scoped to its name: using different names ensures that data does not leak between storages.
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.
28
31
29
-
!!! note "Web platform"
32
+
!!! note "Web"
30
33
31
-
On Web, AsyncStorage is backed by [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API), which also support scoped storages.
34
+
On the Web, AsyncStorage uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API), which supports scoped storages.
32
35
33
-
!!! warning "Windows platform"
36
+
!!! warning "Windows"
34
37
35
-
As of AsyncStorage v3.0, Windows platform does not support scoped storages. It falls back to previous implementation - single storage per application.
38
+
Windows does not support scoped storages. It falls back to the previous v2 implementation, which provides a single storage per application.
36
39
37
40
## Using a storage
38
41
39
-
Once you have created a storage instance, you can start managing data.
42
+
After creating a storage instance, the storage is ready to use.
40
43
41
44
### Single item operations
42
45
43
46
You can store, retrieve, and remove individual keys using `setItem`, `getItem`, and `removeItem`.
44
47
45
48
Note that:
46
49
47
-
-Calling `setItem`with an existing key will overwrite the current value
48
-
-Calling `removeItem`on a key that does not exist has no effect and does not throw an error
50
+
-`setItem`overwrites the current value if the key already exists.
51
+
-`removeItem`does nothing if the key does not exist; it does not throw an error.
49
52
50
53
```typescript
51
54
awaituserStorage.setItem("username", "doe_john");
@@ -66,7 +69,12 @@ console.log(username); // null
66
69
67
70
### Batch operations
68
71
69
-
Use convenient batch methods to handle multiple keys at once. Behind the scene, transaction performed to store all of them, or none in case of an error.
72
+
Use batch methods to handle multiple keys at once. These operations are performed atomically: either all changes are
73
+
applied, or none if an error occurs.
74
+
75
+
-`setMany` stores multiple key-value pairs.
76
+
-`getMany` retrieves multiple keys at once, returning `null` for any keys that don’t exist.
77
+
-`removeMany` deletes multiple keys; non-existing keys are ignored without errors.
Copy file name to clipboardExpand all lines: docs/index.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,28 @@ title: Overview
4
4
5
5
# Async Storage
6
6
7
-
Async Storage is asynchronous, unencrypted, persistent, key-value storage for your React Native application.
8
-
It provides a simple API compatible with the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API), with a few extensions for batch operations and multi-database support.
7
+
Async Storage is an asynchronous, unencrypted, persistent key-value storage solution for your React Native application.
8
+
It provides a simple API compatible with the [Web Storage API]((https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API)), with additional extensions for batch operations and multi-database support.
Copy file name to clipboardExpand all lines: docs/migration-to-3.md
+35-16Lines changed: 35 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,20 @@
1
1
# Migration to v3
2
2
3
-
AsyncStorage v3 introduces some breaking changes to simplify the API and make it more consistent.
3
+
AsyncStorage v3 introduces a few breaking changes to simplify the API and make it more consistent.
4
4
5
5
## Key changes:
6
6
7
7
### Installation changes
8
8
9
-
Android requires local maven repo to be added in your `build.gradle(.kts)` file. Head over to [Installation step for Android](index.md#android) to learn more.
10
-
9
+
Android requires a local Maven repository to be added to your `build.gradle(.kts)` file. Head over to the [Installation step for Android](index.md#android) to learn more.
11
10
12
11
### `AsyncStorage` is now instance-based
13
12
14
13
In v3, AsyncStorage is no longer a singleton.
15
-
Each instance represents an **isolated storage area**, providing separation between data sets. Head over to [Usage page](api/usage.md#creating-a-storage) to learn more.
14
+
Each instance represents an **isolated storage area**, providing separation between data sets. Head over to the [Usage page](api/usage.md#creating-a-storage) to learn more.
The old callback arguments have been removed to make the API simpler and more consistent.
41
40
42
41
### Removed merge functionality
43
42
44
-
AsyncStorage's "merge" behavior has historically been inconsistent across platforms. Rather than enforcing a platform-specific merging strategy, the merge API has been removed to avoid ambiguity.
43
+
AsyncStorage's "merge" behavior has historically been inconsistent across platforms.
44
+
Rather than enforcing a platform-specific merging strategy, the merge API has been removed to avoid ambiguity.
45
+
46
+
### Removed `useAsyncStorage` hook
47
+
48
+
The `useAsyncStorage` hook has been removed due to implementation issues.
49
+
It will be reintroduced in a future release with an improved design.
All errors now thrown from `AsyncStorage` are instances of `AsyncStorageError` containing `type` of the error it represents. Head over to [Errors page](api/errors.md) to learn more.
66
+
All errors thrown by `AsyncStorage` are now instances of `AsyncStorageError`, each containing a `type` property that indicates the kind of error.
67
+
For more details, head over to the [Errors page](api/errors.md).
49
68
50
69
### Method signature changes
51
70
52
-
The core methods
71
+
The core methods:
53
72
54
73
-`getItem`
55
74
-`setItem`
56
75
-`removeItem`
57
76
-`getAllKeys`
58
77
-`clear`
59
78
60
-
retain their signatures from v2, ensuring backward compatibility.
79
+
retain their signatures as in v2, ensuring backward compatibility.
61
80
62
81
#### multiGet
63
82
64
-
Renamed to `getMany` and returns a `Record<string, string | null>`, following a "what you request is what you get" rule: every key you pass in the request appears in the returned object, with `null` for keys that don’t exist in storage.
83
+
Renamed to `getMany`, this method returns a `Record<string, string | null>` and follows a "what you request is what you get" rule: every key provided in the request appears in the returned object, with `null` for keys that don’t exist, or have `null` value, in storage.
65
84
66
85
```diff
67
86
- multiGet: (
@@ -74,7 +93,7 @@ Renamed to `getMany` and returns a `Record<string, string | null>`, following a
74
93
75
94
#### multiSet
76
95
77
-
Renamed to `setMany`, accepts a `Record<string, string>`of key-value entries.
96
+
Renamed to `setMany`, this method accepts a `Record<string, string>`containing key-value pairs.
78
97
79
98
```diff
80
99
- multiSet: (
@@ -87,7 +106,7 @@ Renamed to `setMany`, accepts a `Record<string, string>` of key-value entries.
87
106
88
107
#### multiRemove
89
108
90
-
Renamed to `removeMany`, accepts list of keys.
109
+
Renamed to `removeMany`, this method accepts a list of keys to remove.
0 commit comments