Skip to content

Commit 4a1d92f

Browse files
committed
Add API docs for miniSerializeError and copyWithStructuralSharing
1 parent bdc4e3f commit 4a1d92f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/api/otherExports.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ console.log(nanoid())
2222
// 'dgPXxUz_6fWIQBD8XmiSy'
2323
```
2424

25+
### `miniSerializeError`
26+
27+
The default error serialization function used by `createAsyncThunk`, based on https://github.com/sindresorhus/serialize-error. If its argument is an object (such as an `Error` instance), it returns a plain JS `SerializedError` object that copies over any of the listed fields. Otherwise, it returns a stringified form of the value: `{ message: String(value) }`.
28+
29+
```ts no-transpile
30+
export interface SerializedError {
31+
name?: string
32+
message?: string
33+
stack?: string
34+
code?: string
35+
}
36+
37+
export function miniSerializeError(value: any): SerializedError {}
38+
```
39+
40+
### `copyWithStructuralSharing`
41+
42+
A utility that will recursively merge two similar objects together, preserving existing references if the values appear to be the same. This is used internally to help ensure that re-fetched data keeps using the same references unless the new data has actually changed, to avoid unnecessary re-renders. Otherwise, every re-fetch would likely cause the entire dataset to be replaced and all consuming components to always re-render.
43+
44+
If either of the inputs are not plain JS objects or arrays, the new value is returned.
45+
46+
```ts no-transpile
47+
export function copyWithStructuralSharing<T>(oldObj: any, newObj: T): T
48+
export function copyWithStructuralSharing(oldObj: any, newObj: any): any {}
49+
```
50+
2551
## Exports from Other Libraries
2652

2753
### `createNextState`

0 commit comments

Comments
 (0)