@@ -4,29 +4,45 @@ import React from "react";
44import * as Types from "./types" ;
55
66export const withLoader = <
7- P extends Record < string , any > ,
8- R extends unknown ,
9- Q extends Types . _Q ,
10- D extends Types . _D ,
11- E extends Types . _E ,
12- A = never
7+ TProps extends Record < string , any > ,
8+ TReturn extends unknown ,
9+ TQueries extends Types . _TQueries ,
10+ TDeferred extends Types . _TDeferred ,
11+ TPayload extends Types . _TPayload ,
12+ TArg = never
1313> (
14- Component : Types . ComponentWithLoaderData < P , R > ,
15- loader : Types . Loader < P , R , Q , D , E , A >
16- ) : Types . Component < P > => {
17- let CachedComponent : Types . ComponentWithLoaderData < P , R > ;
18- const LoadedComponent = ( props : P ) => {
14+ Component : Types . ComponentWithLoaderData < TProps , TReturn > ,
15+ loader : Types . Loader <
16+ TProps ,
17+ TReturn ,
18+ TQueries ,
19+ TDeferred ,
20+ TPayload ,
21+ TArg
22+ >
23+ ) : Types . Component < TProps > => {
24+ let CachedComponent : Types . ComponentWithLoaderData <
25+ TProps ,
26+ TReturn
27+ > ;
28+ const LoadedComponent = ( props : TProps ) => {
1929 const useLoaderArgs = [ ] ;
2030 if ( loader . queriesArg ) {
2131 useLoaderArgs . push ( loader . queriesArg ( props ) ) ;
2232 }
2333 const query = loader . useLoader (
24- ...( useLoaderArgs as Types . OptionalGenericArg < A > )
34+ ...( useLoaderArgs as Types . OptionalGenericArg < TArg > )
2535 ) ;
2636 if ( ! CachedComponent ) {
2737 CachedComponent = React . forwardRef (
28- Component as React . ForwardRefRenderFunction < R , P >
29- ) as unknown as Types . ComponentWithLoaderData < P , R > ;
38+ Component as React . ForwardRefRenderFunction <
39+ TReturn ,
40+ TProps
41+ >
42+ ) as unknown as Types . ComponentWithLoaderData <
43+ TProps ,
44+ TReturn
45+ > ;
3046 }
3147
3248 const onLoading = loader . onLoading ?.( props ) ;
@@ -42,7 +58,7 @@ export const withLoader = <
4258 }
4359 : undefined ;
4460
45- const onSuccess = ( data : R ) => (
61+ const onSuccess = ( data : TReturn ) => (
4662 < CachedComponent { ...props } ref = { data } />
4763 ) ;
4864
@@ -62,7 +78,7 @@ export const withLoader = <
6278 const onFetching = loader ?. onFetching ?.(
6379 props ,
6480 query . data
65- ? ( ) => onSuccess ( query . data as R )
81+ ? ( ) => onSuccess ( query . data as TReturn )
6682 : ( ) => < React . Fragment />
6783 ) ;
6884
0 commit comments