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/docs/Advanced/under-the-hood.md
+11-17Lines changed: 11 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,17 @@
2
2
3
3
How does `rtk-query-loader` work _under the hood_?
4
4
5
+
## The underlying principles
6
+
7
+
1. We have a higher-order component (wrapper)
8
+
2. We aggregate the status of a collection of queries that are run through a hook
9
+
3. We conditionally render the appropriate states
10
+
4. We pass the data to the consumer-component through the use of `React.forwardRef`
11
+
12
+
### Can't I just build this myself?
13
+
14
+
Yes you can, the concept itself is quite simple. But making it properly type-safe can be difficult, and this package has been thoroughly tested and thought out. And we do offer some killer [features](../Features/index.md).
15
+
5
16
## Virtual DOM
6
17
7
18
Imagine you have this component, rendered through `withLoader`:
@@ -59,20 +70,3 @@ div
59
70
## RTKLoader
60
71
61
72
`RTKLoader` simply receives the loader and component, and handles returning the correct state depending on the query. You can take a look at how this component behaves [in the codebase](https://github.com/ryfylke-react-as/rtk-query-loader/blob/main/src/RTKLoader.tsx).
62
-
63
-
## Custom `loaderComponent`
64
-
65
-
You could pass a custom `loaderComponent` to your loaders, if you'd like:
Deferred queries are not automatically passed to the output of the loader, you have to use the `transform` argument (and it's second argument) to expose the queries for the consumers. The format of how you transform it is not important, but it is the only way to _get_ the deferred query result out of the loader.
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 `queries` 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 `queries` argument will properly overwrite the existing base properties.
24
+
:::caution
25
+
`.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.
You can use RTK Query Loader with most other similar query-fetching libraries. This is possible through the use of _resolvers_.
8
+
9
+
:::note
10
+
Although `rtk-query-loader` was build with `@reduxjs/toolkit` in mind, the underlying principles can be applied to any similar data loading solution. [Read more about how RTK Query Loader works under the hood](../Advanced/under-the-hood.md).
The output format will obviously be a bit different, but in this example you have access to the original query at the `.original_query` property.
71
+
72
+
## Other libraries
73
+
74
+
If you are interested in creating resolvers for other libraries, you can [edit this page](https://github.com/ryfylke-react-as/rtk-query-loader/tree/main/docs/docs/Advanced/other-libs.md) and then [submit a pull request](https://github.com/ryfylke-react-as/rtk-query-loader/compare) on GitHub to share your resolver here, as an npm package, or with the code embedded directly in the docs.
0 commit comments