Skip to content

Commit b3e3d27

Browse files
committed
docs: updated extend docs after new feature
1 parent 61b12ac commit b3e3d27

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

docs/docs/Features/extending.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,36 @@ const parentLoader = createLoader({
1313

1414
const childLoader = parentLoader.extend({
1515
useQueries: () => ({...}),
16-
})
16+
onError: () => <div>Error</div>,
17+
}).extend({
18+
transform: () => ({...}),
19+
}).extend({
20+
onLoading: () => <div>Overwritten loading...</div>,
21+
});
1722
```
1823

19-
It's worth mentioning that queries and transform are linked in this context, meaning that if you supply a new queries argument in the extended loader, but no transform, then you will not inherit the transform from the original loader.
20-
21-
- Supplying just a new `useQueries` argument will result in transform being undefined in practise.
22-
- Supplying just a new `transform` argument will result in the new transform being ignored.
23-
- Supplying a new `transform` and a new `useQueries` argument will properly overwrite the existing base properties.
24-
25-
All other properties in the loader will overwrite as expected. You can, for example, just supply a new `onLoading`, or `onError`.
26-
24+
:::caution
2725
`.extend` will not merge two separate `useQueries` properties. For example, you cannot _just_ inherit the deferredQueries, you must either inherit all or none of the `useQueries` argument.
26+
:::
27+
:::tip Reusable transformers
28+
You can extend as many times as you'd like. You can use this feature to easily inject reusable snippets, like transformers.
29+
30+
```typescript
31+
type QueryRecord = Record<string, UseQueryResult<unknown>>;
32+
33+
export const transformData = {
34+
transform: (data: {
35+
queries: QueryRecord;
36+
deferredQueries: QueryRecord;
37+
payload: unknown;
38+
}) => {
39+
// handle transformation in generic way
40+
},
41+
};
42+
```
43+
44+
```typescript
45+
const loader = createLoader({...}).extend(transformData);
46+
```
2847

29-
:::info
30-
You may extend _extended_ loaders, to create an inheritance model.
3148
:::

0 commit comments

Comments
 (0)