File tree 4 files changed +31
-3
lines changed
test-apps/testing-app/app/routes
4 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,20 @@ clientLoader.hydrate = true;
244
244
245
245
```
246
246
247
+ ### createClientLoaderCache
248
+
249
+ Creates everything needed to cache the data via clientLoader, behind the scenes creates the clientLoader object with the correct hydrate flag and the adapter.
250
+
251
+ ``` tsx
252
+ import { createClientLoaderCache , cacheClientLoader } from " remix-client-cache" ;
253
+
254
+ export const clientLoader = createClientLoaderCache ();
255
+
256
+ // above is equivalent to:
257
+ export const clientLoader = (args : ClientLoaderFunctionArgs ) => cacheClientLoader (args );
258
+ clientLoader .hydrate = true ;
259
+ ```
260
+
247
261
### decacheClientLoader
248
262
249
263
Used to remove the data that is piped from the loader to your component using the ` clientLoader ` export.
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " remix-client-cache" ,
3
- "version" : " 2.0.1 " ,
3
+ "version" : " 2.1.0 " ,
4
4
"description" : " Utility library to cache your client data in React Router" ,
5
5
"type" : " module" ,
6
6
"main" : " ./dist/index.cjs" ,
Original file line number Diff line number Diff line change @@ -79,13 +79,19 @@ export const decacheClientLoader = async <T,>(
79
79
return data ;
80
80
} ;
81
81
82
+ type CacheClientLoaderArgs = {
83
+ type ?: "swr" | "normal" ;
84
+ key ?: string ;
85
+ adapter ?: CacheAdapter ;
86
+ } ;
87
+
82
88
export const cacheClientLoader = async < T , > (
83
89
{ request, serverLoader } : ClientLoaderFunctionArgs ,
84
90
{
85
91
type = "swr" ,
86
92
key = constructKey ( request ) ,
87
93
adapter = cache ,
88
- } : { type ?: "swr" | "normal" ; key ?: string ; adapter ?: CacheAdapter } = {
94
+ } : CacheClientLoaderArgs = {
89
95
type : "swr" ,
90
96
key : constructKey ( request ) ,
91
97
adapter : cache ,
@@ -119,6 +125,13 @@ export const cacheClientLoader = async <T,>(
119
125
} ;
120
126
} ;
121
127
128
+ export const createClientLoaderCache = ( props ?: CacheClientLoaderArgs ) => {
129
+ const clientLoader = ( args : ClientLoaderFunctionArgs ) =>
130
+ cacheClientLoader ( args , props ) ;
131
+ clientLoader . hydrate = true ;
132
+ return clientLoader ;
133
+ } ;
134
+
122
135
export function useCachedLoaderData < T > (
123
136
{ adapter = cache } : { adapter ?: CacheAdapter } = { adapter : cache } ,
124
137
) {
Original file line number Diff line number Diff line change 7
7
import type { MetaFunction } from "react-router" ;
8
8
import {
9
9
cacheClientLoader ,
10
+ createClientLoaderCache ,
10
11
decacheClientLoader ,
11
12
useCachedLoaderData ,
12
13
} from "remix-client-cache" ;
@@ -25,7 +26,7 @@ export const loader = async () => {
25
26
return { user : { description : Math . random ( ) } } ;
26
27
} ;
27
28
28
- export const clientLoader = cacheClientLoader ;
29
+ export const clientLoader = createClientLoaderCache ( ) ;
29
30
clientLoader . hydrate = true ;
30
31
31
32
export const clientAction = decacheClientLoader ;
You can’t perform that action at this time.
0 commit comments