Skip to content

Commit

Permalink
version: 0.3.37
Browse files Browse the repository at this point in the history
  • Loading branch information
imp-dance committed Nov 26, 2022
1 parent e247245 commit 2a444b9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 59 deletions.
56 changes: 0 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,6 @@ const Component = withLoader(
2. `Loader`
Return value of `createLoader`.

### Extending/customizing the loader

To use an existing loader but with maybe a different loading state, for example:

```tsx

const Component = withLoader(
(props: Props, loaderData) => {
// Can safely assume that loaderData and props are populated.
const posts = loaderData.posts;

return posts.map(,,,);
},
postsLoader.extend({
onLoading: (props) => <props.loader />,
onFetching: (props) => <props.loader />,
}),
)

```

## createUseLoader

Creates only the hook for the loader, without the extra metadata like loading state.
Expand Down Expand Up @@ -247,38 +226,3 @@ const pokemonLoader = baseLoader.extend({
```

New properties will overwrite existing.

**NOTE**:

> 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:
```typescript
const baseLoader = createLoader({
queries: () => [...],
transform: () => {i_want: "this-format"},
})

// This first example is extending a loader that has a transform.
// It does not supply a new transform function
const extendedOne = baseLoader.extend(({
queries: () => [...],
}))

type TestOne = InferLoaderData<typeof extendedOne>;
// Resolves to: { i_want: string; }
// which is incorrect. In reality it defaults to your list of queries.

// In this example, we supply a transform function as well:
const extendedTwo = baseLoader.extend({
queries: () => [...],
transform: (q) => q, // This is essentially the default value
});

type TestTwo = InferLoaderData<typeof extendedTwo>;
// Resolves to: readonly [UseQueryResult<...>]
// which is correct.
```

> 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.
## [**Contributing guidelines**](https://github.com/ryfylke-react-as/rtk-query-loader/blob/main/CONTRIBUTING.md)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ryfylke-react/rtk-query-loader",
"version": "0.3.36",
"version": "0.3.37",
"description": "Lets you create reusable, extendable RTK loaders for React components.",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ export type Loader<
LoaderComponent: Component<CustomLoaderProps>;
};

/** Legacy/unused, for backwards compatibility */

/************************************************/
/* Legacy/unused, for backwards compatibility */
/************************************************/
export type WithLoaderArgs<
P extends unknown,
R extends unknown,
Expand Down

0 comments on commit 2a444b9

Please sign in to comment.