Skip to content

Commit a7bddb0

Browse files
committed
docs: improvements
1 parent 945deba commit a7bddb0

File tree

6 files changed

+100
-69
lines changed

6 files changed

+100
-69
lines changed

docs/api/brownfield.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
!!! info
22

3-
Brownfield integration is supported on **Android**, **iOS** and **macOS**.
3+
Brownfield integration is supported on **Android**, **iOS**, and **macOS**.
44

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.
79

810
All platforms provide a thread-safe singleton registry called `StorageRegistry` to manage storage instances.
911

1012
### Android
1113

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.
1315
Multiple calls with the same name return the same singleton instance, ensuring consistent access.
1416

1517
```kotlin
@@ -30,7 +32,7 @@ runBlocking {
3032

3133
### iOS / macOS
3234

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.
3436

3537
```swift
3638
import SharedAsyncStorage

docs/api/db-naming.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
## How `databaseName` is used
22

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.
56

67
### iOS & macOS
78

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
11+
subdirectory inside `async-storage/databases`.
1112

1213
Directory:
1314

@@ -33,9 +34,9 @@ createAsyncStorage(`user-${userId}`);
3334

3435
### Android
3536

36-
On Android, databases are stored inside the app’s internal files directory.
37-
The `databaseName` is normalized into a file path with the `.sqlite` extension.
38-
Each `databaseName` creates its own subdirectory inside `async-storage/databases`.
37+
On Android, databases are stored in the app’s internal files directory.
38+
The `databaseName` is normalized into a file path with the `.sqlite` extension, and each `databaseName` creates its own
39+
subdirectory inside `async-storage/databases`.
3940

4041
Directory:
4142

@@ -61,8 +62,8 @@ createAsyncStorage(`user-${userId}`);
6162

6263
### Web
6364

64-
On Web, `databaseName` corresponds directly to the name of the IndexedDB database.
65-
The `async-storage` grouping is abstracted away, but the uniqueness of the name is still guaranteed.
65+
On the Web, `databaseName` corresponds directly to the name of the IndexedDB database.
66+
Although the `async-storage` grouping is abstracted away, the name remains unique across instances.
6667

6768
Example:
6869

@@ -77,5 +78,5 @@ Creates database named `user-1234`:
7778

7879
### Windows
7980

80-
On Windows, scoped storages are not supported.
81-
The API always falls back to the legacy v2 storage implementation, which ignores `databaseName`.
81+
On the Web, `databaseName` corresponds directly to the name of the IndexedDB database.
82+
Although the `async-storage` grouping is abstracted away, the name remains unique across instances.

docs/api/errors.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
# Error handling
22

3-
All `AsyncStorage` methods throw a specialized error type, `AsyncStorageError`.
4-
This class extends the standard `Error` class, by adding a `type` property to help identify the issue.
3+
All `AsyncStorage` methods throw a specialized error type called `AsyncStorageError`.
4+
This class extends the standard `Error` class and adds a `type` property to make it easier to identify the specific
5+
issue.
56

67
## Error types
78

8-
The error type is an enum `AsyncStorageError.Type` with the following possible values:
9+
Errors are categorized using the `AsyncStorageError.Type` enum, which includes the following values:
910

1011
### NativeModuleError
1112

12-
Raised when the RN native module itself fails for example,
13-
the module is null at app startup, or not initialized correctly.
13+
Occurs when the React Native native module fails - for example, if the module is null at app startup or not initialized
14+
correctly.
1415

1516
### WebStorageError
1617

17-
Web only, when an IndexedDB operation fails.
18-
[See IndexedDB error codes](https://developer.mozilla.org/en-US/docs/Web/API/IDBRequest/error.
18+
Occurs on the Web when an IndexedDB operation fails.
19+
[See IndexedDB error codes](https://developer.mozilla.org/en-US/docs/Web/API/IDBRequest/errori)
1920

2021
### SqliteStorageError
2122

22-
Raised when SQLite itself fails on iOS, macOS, or Android.
23-
[See SQLite error codes](https://www.sqlite.org/rescode.html).
23+
Occurs when SQLite itself fails on iOS, macOS, or Android.
24+
[See SQLite error codes](https://www.sqlite.org/rescode.html)
2425

2526
### OtherStorageError
2627

27-
Raised for other storage-related failures that don’t fit into the categories above.
28+
Used for storage-related failures that don’t fall into the other categories.
2829
Examples include:
2930

3031
- Storage not initialized correctly
@@ -35,7 +36,7 @@ Examples include:
3536

3637
### UnknownError
3738

38-
A catch-all for cases where the system cannot classify the error.
39+
A catch-all for errors that cannot be classified into any of the defined categories.
3940

4041
## Example of error handling
4142

docs/api/usage.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,51 @@ title: Usage
44

55
# Using Async Storage
66

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.
7+
The [
8+
`AsyncStorage`](https://github.com/react-native-async-storage/async-storage/blob/main/packages/async-storage/src/AsyncStorage.ts)
9+
interface provides a promise-based API for persistent key-value storage.
10+
It mirrors the Web Storage API, with additional support for batch operations.
911

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.
1114

1215
## Creating a storage
1316

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:
1518

16-
!!! note "About naming"
19+
!!! note "Naming"
1720

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.
1922

2023
```typescript
2124
import { createAsyncStorage } from "@react-native-async-storage/async-storage";
2225

2326
const userStorage = createAsyncStorage("john");
2427
```
2528

26-
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.
2831

29-
!!! note "Web platform"
32+
!!! note "Web"
3033

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.
3235

33-
!!! warning "Windows platform"
36+
!!! warning "Windows"
3437

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.
3639

3740
## Using a storage
3841

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.
4043

4144
### Single item operations
4245

4346
You can store, retrieve, and remove individual keys using `setItem`, `getItem`, and `removeItem`.
4447

4548
Note that:
4649

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.
4952

5053
```typescript
5154
await userStorage.setItem("username", "doe_john");
@@ -66,7 +69,12 @@ console.log(username); // null
6669

6770
### Batch operations
6871

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.
7078

7179
```typescript
7280
// store values
@@ -89,9 +97,9 @@ console.log(data);
8997
await userStorage.removeMany(["email", "age", "not-here"]);
9098
```
9199

92-
### Reading stored keys
100+
### Read all keys
93101

94-
To retrieve all keys currently stored in a storage instance, use `getAllKeys`:
102+
To retrieve all keys currently used in the storage instance, use `getAllKeys`:
95103

96104
```typescript
97105
await userStorage.setMany({

docs/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ title: Overview
44

55
# Async Storage
66

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.
99

1010
---
1111

12-
## Supported platforms
12+
## Supported Platforms
1313

1414
- **Android** (SQLite backend via Room KMP)
1515
- **iOS** (SQLite backend via Room KMP)
1616
- **Web** (IndexedDB backend)
1717
- **macOS** (SQLite backend via Room KMP)
18-
- **Windows** (legacy fallback, single database only)
18+
- **Windows** (legacy fallback, single-database only)
1919

2020
---
2121

2222
## Installation
2323

2424
```shell
25-
# using npm
25+
# Using npm
2626
npm install @react-native-async-storage/async-storage
2727

28-
# using yarn
28+
# Using yarn
2929
yarn add @react-native-async-storage/async-storage
3030
```
3131

@@ -36,7 +36,7 @@ Inside your `android/build.gradle(.kts)` file, add link to local maven repo:
3636
```groovy
3737
allprojects {
3838
repositories {
39-
// ... others like google(), mavenCenterl()
39+
// ... others like google(), mavenCentral()
4040
4141
maven {
4242
// or uri("path/to/node_modules/@react-native-async-storage/async-storage/android/local_repo")

docs/migration-to-3.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# Migration to v3
22

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.
44

55
## Key changes:
66

77
### Installation changes
88

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.
1110

1211
### `AsyncStorage` is now instance-based
1312

1413
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.
1615

1716
```typescript
18-
// create seperate storages
17+
// create separate storages
1918
const userStorage = createAsyncStorage('user');
2019
const cacheStorage = createAsyncStorage('cache');
2120
```
@@ -25,43 +24,63 @@ const cacheStorage = createAsyncStorage('cache');
2524
To make upgrading smoother, the default export continues to reference the v2 implementation.
2625
This ensures that:
2726

28-
- Your app continues to access previously stored data.
27+
- Your app can continue to access previously stored data.
2928
- You can migrate incrementally to v3 instances.
3029

3130
```typescript
32-
// Still works (uses v2 backend)
31+
// Still works (uses the v2 backend)
3332
import AsyncStorage from '@react-native-async-storage/async-storage';
3433
await AsyncStorage.setItem('foo', 'bar');
3534
```
3635

37-
### Callbacks removed Promises only
36+
### Callbacks removed - Promises only
3837

39-
All methods are now Promise-based.
38+
All methods are now promise-based.
4039
The old callback arguments have been removed to make the API simpler and more consistent.
4140

4241
### Removed merge functionality
4342

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.
50+
51+
If you need it, here's the old version:
52+
53+
```typescript
54+
export function useAsyncStorage(key: string): AsyncStorageHook {
55+
return {
56+
getItem: (...args) => AsyncStorage.getItem(key, ...args),
57+
setItem: (...args) => AsyncStorage.setItem(key, ...args),
58+
mergeItem: (...args) => AsyncStorage.mergeItem(key, ...args),
59+
removeItem: (...args) => AsyncStorage.removeItem(key, ...args),
60+
};
61+
}
62+
```
4563

4664
### Errors are more predictable now
4765

48-
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).
4968

5069
### Method signature changes
5170

52-
The core methods
71+
The core methods:
5372

5473
- `getItem`
5574
- `setItem`
5675
- `removeItem`
5776
- `getAllKeys`
5877
- `clear`
5978

60-
retain their signatures from v2, ensuring backward compatibility.
79+
retain their signatures as in v2, ensuring backward compatibility.
6180

6281
#### multiGet
6382

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.
6584

6685
```diff
6786
- multiGet: (
@@ -74,7 +93,7 @@ Renamed to `getMany` and returns a `Record<string, string | null>`, following a
7493

7594
#### multiSet
7695

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.
7897

7998
```diff
8099
- multiSet: (
@@ -87,7 +106,7 @@ Renamed to `setMany`, accepts a `Record<string, string>` of key-value entries.
87106

88107
#### multiRemove
89108

90-
Renamed to `removeMany`, accepts list of keys.
109+
Renamed to `removeMany`, this method accepts a list of keys to remove.
91110

92111
```diff
93112
- multiRemove: (

0 commit comments

Comments
 (0)