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/migration-to-3.md
+40-14Lines changed: 40 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,23 +2,52 @@
2
2
3
3
AsyncStorage v3 introduces some breaking changes to simplify the API and make it more consistent.
4
4
5
-
## AsyncStorage instance needs to be created now
5
+
## Key changes:
6
6
7
-
AsyncStorage v3 introduced scoped storages, which needs to be created before use. Head to [Usage page](api/usage.md#creating-a-storage) to learn more.
7
+
### Installation changes
8
8
9
-
## Default export points to v2 storage
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
10
11
-
To make transition easier, the default export still points to the v2 storage implementation, ensuring that no existing data is lost.
12
11
13
-
##Removed callback arguments
12
+
### `AsyncStorage` is now instance-based
14
13
15
-
All methods now return Promises, and callbacks have been removed from all methods.
14
+
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.
16
16
17
-
## Removed merge functionality
17
+
```typescript
18
+
// create seperate storages
19
+
const userStorage =createAsyncStorage('user');
20
+
const cacheStorage =createAsyncStorage('cache');
21
+
```
22
+
23
+
### Default export still points to v2 storage
24
+
25
+
To make upgrading smoother, the default export continues to reference the v2 implementation.
26
+
This ensures that:
27
+
28
+
- Your app continues to access previously stored data.
The old callback arguments have been removed to make the API simpler and more consistent.
41
+
42
+
### Removed merge functionality
18
43
19
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.
20
45
21
-
## Method signature changes
46
+
### Errors are more predictable now
47
+
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.
49
+
50
+
### Method signature changes
22
51
23
52
The core methods
24
53
@@ -30,7 +59,7 @@ The core methods
30
59
31
60
retain their signatures from v2, ensuring backward compatibility.
32
61
33
-
### multiGet
62
+
####multiGet
34
63
35
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.
36
65
@@ -43,7 +72,7 @@ Renamed to `getMany` and returns a `Record<string, string | null>`, following a
@@ -69,6 +98,3 @@ Renamed to `removeMany`, accepts list of keys.
69
98
+ removeMany(keys: string[]): Promise<void>;
70
99
```
71
100
72
-
## Errors are more predictable now
73
-
74
-
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.
0 commit comments