Skip to content

Commit 14ec768

Browse files
committed
docs: Updated docs
1 parent 93af03c commit 14ec768

File tree

17 files changed

+222
-91
lines changed

17 files changed

+222
-91
lines changed

docs/docs/Exports/create-loader.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/docs/Exports/with-loader.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/docs/Features/index.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ RTK Query Loader tries to give you all the flexibility you need to create reusab
1313
- Send down payloads that contain any static data.
1414
- [Transform](./transforming.md) the data to your desired output-format.
1515
- Set up [default](../Quick%20Guide/base-loader.md) loading and error states.
16-
- [Extend](./extending.md) existing loaders.
17-
- Re-use existing loaders
16+
- [Extend](./extending.md) and re-use existing loaders.
1817
- Create [stateful loaders](./stateful-loader)
1918

2019
And even if you don't use `RTK Query`...
2120

22-
- Supply queries that are [just promises](../Exports/use-create-query.md).
21+
- Supply queries that are [just promises](../Reference/use-create-query.md).
2322
- [Use with other data loading libraries](./other-libs.md)
2423

2524
---

docs/docs/Migrations/v0.x.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const Consumer = withLoader((props, data) => {
104104
}, loader);
105105
```
106106

107-
Previously, if you wanted to do something like this, you had to use [useCreateQuery](../Exports/use-create-query.md), or a wrapper component. If you did, you can now refactor your code to use `payload` instead, which should be a lot more clean and flexible.
107+
Previously, if you wanted to do something like this, you had to use [useCreateQuery](../Reference/use-create-query.md), or a wrapper component. If you did, you can now refactor your code to use `payload` instead, which should be a lot more clean and flexible.
108108

109109
## Change: Extend transform
110110

docs/docs/Quick Guide/add-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_position: 3
66

77
You can now start to add queries to your extended loaders.
88

9-
The `useQueries` argument of [createLoader](/Exports/create-loader) is a _hook_, which means that [the rules of hooks](https://reactjs.org/docs/hooks-rules.html) apply. This gives you the super-power of utilizing other hooks inside of your loader.
9+
The `useQueries` argument of [createLoader](/Reference/create-loader) is a _hook_, which means that [the rules of hooks](https://reactjs.org/docs/hooks-rules.html) apply. This gives you the super-power of utilizing other hooks inside of your loader.
1010

1111
```tsx title="/src/loaders/userRouteLoader.tsx" {6-15}
1212
import { baseLoader } from "./baseLoader";

docs/docs/Quick Guide/extend-loader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { baseLoader } from "./baseLoader";
1212
export const userRouteLoader = baseLoader.extend({});
1313
```
1414

15-
You can pass any argument from [`createLoader`](/Exports/create-loader) into [`Loader.extend`](/Features/extending).
15+
You can pass any argument from [`createLoader`](/Reference/create-loader) into [`Loader.extend`](/Features/extending).
1616

1717
:::info Separation of concerns
1818
Its up to you how much you want to separate logic here. Some examples would be...
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ sidebar_position: 6
44

55
# aggregateToQuery
66

7-
Aggregated a set of `UseQueryResult` into a single query.
8-
9-
:::caution
10-
`aggregateToQuery` does not add any `data` to the resulting query. You will have to do that manually afterwards.
11-
:::
7+
Aggregates a set of `UseQueryResult` into a single query.
128

139
```typescript
1410
import {
@@ -27,3 +23,7 @@ const query: UseQueryResult<unknown> = {
2723
data: queries.map((query) => query.data),
2824
};
2925
```
26+
27+
:::caution
28+
`aggregateToQuery` does not add any `data` to the resulting query. You will have to do that manually afterwards.
29+
:::
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# createLoader
6+
7+
Creates a `Loader`.
8+
9+
## Arguments
10+
11+
All arguments are optional.
12+
13+
- **`useQueries`** - A hook that runs the queries and returns them. It can take an argument, which can be transformed from the consumer props through `queriesArg`
14+
```typescript
15+
useQueries: (arg?: Arg) => {
16+
queries?: Record<string, UseQueryResult>;
17+
deferredQueries?: Record<string, UseQueryResult>;
18+
payload?: any;
19+
}
20+
```
21+
- **`queriesArg`** - A function that transforms the consumer props into the argument for `useQueries` - required if your loader should be able to take arguments from props.
22+
```typescript
23+
queriesArg: (props: Props) => Arg;
24+
```
25+
- **`transform`** - A function that lets you transform the shape of the output data.
26+
```typescript
27+
transform: (data: Data) => TransformedData;
28+
```
29+
- **`onLoading`** - A function that determines what to render while the component is going through it's initial load phase.
30+
```typescript
31+
onLoading: (props: Props) => ReactElement;
32+
```
33+
- **`onError`** - A function that determines what to render while the component is going through it's initial load phase.
34+
```typescript
35+
onError: (props: Props, error: unknown) => ReactElement;
36+
```
37+
- **`whileFetching`** - An object that lets you append &/ prepend elements to your component while it is fetching.
38+
```typescript
39+
whileFetching: {
40+
prepend?: (props: Props, data?: Data) => ReactElement;
41+
append?: (props: Props, data?: Data) => ReactElement;
42+
};
43+
```
44+
- **`config`** - An object that lets you configure the behavior of the loader.
45+
```typescript
46+
config: {
47+
defer? {
48+
shouldThrowError?: boolean;
49+
};
50+
loaderComponent?: Component<LoaderComponentProps>;
51+
}
52+
```
53+
54+
## Return
55+
56+
`createLoader` returns a `Loader`. You can use this loader with [withLoader](with-loader.md), or you can call the `.extend` method to produce a new loader using the original loader as a base. `.extend` takes the same set of arguments as `createLoader`.
57+
58+
## Example usage
59+
60+
```typescript title="example.ts"
61+
type ConsumerProps = Record<string, any> & {
62+
userId: string;
63+
};
64+
65+
const loader = createLoader({
66+
queriesArg: (props: ConsumerProps) => props.userId,
67+
useQueries: (userId) => {
68+
return {
69+
queries: {
70+
user: useGetUser(userId),
71+
},
72+
deferredQueries: {
73+
relations: useGetUserRelations(userId),
74+
},
75+
payload: {
76+
// Lets you send any static data to your consumer
77+
static: "data",
78+
},
79+
};
80+
},
81+
transform: (loaderData) => ({
82+
...loaderData,
83+
foo: "bar",
84+
}),
85+
onLoading: (props) => <LoadingView />,
86+
onError: (props, error) => <ErrorView />,
87+
whileFetching: {
88+
prepend: (props) => <LoadingOverlay />,
89+
},
90+
});
91+
```
92+
93+
:::caution Using version `0.3.51` or earlier?
94+
Please refer to the [**migration guide**](../Migrations/v0.x).
95+
:::
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_position: 6
44

55
import DocCardList from "@theme/DocCardList";
66

7-
# Exports
7+
# Reference
88

99
Describes the different exports and their related types.
1010

0 commit comments

Comments
 (0)