Skip to content

Commit 741bf23

Browse files
committed
version: 0.3.3
1 parent 9dc5949 commit 741bf23

File tree

4 files changed

+7926
-7815
lines changed

4 files changed

+7926
-7815
lines changed

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src
2+
testing-app

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ryfylke-react/rtk-query-loader",
3-
"version": "0.3.26",
3+
"version": "0.3.3",
44
"description": "Lets you create loaders that contain multiple RTK queries.",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",
@@ -21,8 +21,10 @@
2121
"url": "https://github.com/ryfylke-react-as/rtk-query-loader/issues"
2222
},
2323
"homepage": "https://github.com/ryfylke-react-as/rtk-query-loader#readme",
24-
"dependencies": {
25-
"@types/react": "^18.0.21",
24+
"devDependencies": {
25+
"@types/react": "^18.0.21"
26+
},
27+
"peerDependencies": {
2628
"@reduxjs/toolkit": "^1.6.2",
2729
"react": "^18.2.0",
2830
"tslib": "^2.4.0"

src/withLoader.tsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export const withLoader = <
1818
const query = args.useLoader(
1919
...(useLoaderArgs as Types.OptionalGenericArg<A>)
2020
);
21+
22+
const ForwardedComponent = React.useCallback(
23+
React.forwardRef(
24+
Component as React.ForwardRefRenderFunction<R, P>
25+
) as unknown as Types.ComponentWithLoaderData<P, R>,
26+
[]
27+
);
28+
2129
return (
2230
<RTKLoader
2331
query={query}
@@ -32,11 +40,18 @@ export const withLoader = <
3240
) ?? <React.Fragment />
3341
: undefined
3442
}
35-
onSuccess={(data) => Component(props, data)}
43+
onSuccess={(data) => (
44+
<ForwardedComponent {...props} ref={data} />
45+
)}
3646
onFetching={args?.onFetching?.(
3747
props,
3848
query.data
39-
? () => Component(props, query.data as R)
49+
? () => (
50+
<ForwardedComponent
51+
{...props}
52+
ref={query.data as R}
53+
/>
54+
)
4055
: () => <React.Fragment />
4156
)}
4257
/>

0 commit comments

Comments
 (0)