Skip to content

Commit 45a28f0

Browse files
committed
Merge branch 'main' of github.com:imp-dance/rtk-query-loader
2 parents aaac0cb + e9946eb commit 45a28f0

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Actual behavior**
24+
A clear and concise description of what actually happened.
25+
26+
**Screenshots**
27+
If applicable, add screenshots to help explain your problem.
28+
29+
**Device (please complete the following information):**
30+
- OS: [e.g. iOS]
31+
- Browser [e.g. chrome, safari]
32+
- Version [e.g. 22]
33+
34+
**Additional context**
35+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ A simple example of a component using rtk-query-loader:
2121

2222
```tsx
2323
import {
24-
createUseLoader,
25-
RTKLoader,
24+
createLoader,
25+
withLoader,
2626
} from "@ryfylke-react/rtk-query-loader";
2727

2828
const loader = createLoader({
@@ -224,19 +224,35 @@ const pokemonLoader = baseLoader.extend({
224224

225225
New properties will overwrite existing.
226226

227-
> If the loader you extend has a `transform` function, and you are changing the `queries` function, you might need to do this to resolve the types properly:
227+
**NOTE**:
228+
229+
> If the loader that you _extend from_ has a `transform` function, and you are change the `queries` function in the _extended_ loader, you might need to do the following fix to resolve the types correctly:
228230
229231
```typescript
230232
const baseLoader = createLoader({
231233
queries: () => [...],
232234
transform: () => {i_want: "this-format"},
233235
})
234236

235-
const pokemonLoader = baseLoader.extend({
237+
// This first example is extending a loader that has a transform.
238+
// It does not supply a new transform function
239+
const extendedOne = baseLoader.extend(({
240+
queries: () => [...],
241+
}))
242+
243+
type TestOne = InferLoaderData<typeof extendedOne>;
244+
// Resolves to: { i_want: string; }
245+
// which is incorrect. In reality it defaults to your list of queries.
246+
247+
// In this example, we supply a transform function as well:
248+
const extendedTwo = baseLoader.extend({
236249
queries: () => [...],
237-
transform: (q) => q, // Reapply default transform for query
250+
transform: (q) => q, // This is essentially the default value
238251
});
239252

240-
type Test = ReturnType<typeof pokemonLoader.useLoader>;
241-
// { i_want: string; }
253+
type TestTwo = InferLoaderData<typeof extendedTwo>;
254+
// Resolves to: readonly [UseQueryResult<...>]
255+
// which is correct.
242256
```
257+
258+
> This is just a type mistake that will hopefully be fixed in the future. Both `extendedOne` and `extendedTwo` return the same format, but `extendedTwo` has the correct types.

0 commit comments

Comments
 (0)