File tree Expand file tree Collapse file tree 4 files changed +31
-3
lines changed
test-apps/testing-app/app/routes Expand file tree Collapse file tree 4 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,20 @@ clientLoader.hydrate = true;
244244
245245```
246246
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+
247261### decacheClientLoader
248262
249263Used 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 11{
22 "name" : " remix-client-cache" ,
3- "version" : " 2.0.1 " ,
3+ "version" : " 2.1.0 " ,
44 "description" : " Utility library to cache your client data in React Router" ,
55 "type" : " module" ,
66 "main" : " ./dist/index.cjs" ,
Original file line number Diff line number Diff line change @@ -79,13 +79,19 @@ export const decacheClientLoader = async <T,>(
7979 return data ;
8080} ;
8181
82+ type CacheClientLoaderArgs = {
83+ type ?: "swr" | "normal" ;
84+ key ?: string ;
85+ adapter ?: CacheAdapter ;
86+ } ;
87+
8288export const cacheClientLoader = async < T , > (
8389 { request, serverLoader } : ClientLoaderFunctionArgs ,
8490 {
8591 type = "swr" ,
8692 key = constructKey ( request ) ,
8793 adapter = cache ,
88- } : { type ?: "swr" | "normal" ; key ?: string ; adapter ?: CacheAdapter } = {
94+ } : CacheClientLoaderArgs = {
8995 type : "swr" ,
9096 key : constructKey ( request ) ,
9197 adapter : cache ,
@@ -119,6 +125,13 @@ export const cacheClientLoader = async <T,>(
119125 } ;
120126} ;
121127
128+ export const createClientLoaderCache = ( props ?: CacheClientLoaderArgs ) => {
129+ const clientLoader = ( args : ClientLoaderFunctionArgs ) =>
130+ cacheClientLoader ( args , props ) ;
131+ clientLoader . hydrate = true ;
132+ return clientLoader ;
133+ } ;
134+
122135export function useCachedLoaderData < T > (
123136 { adapter = cache } : { adapter ?: CacheAdapter } = { adapter : cache } ,
124137) {
Original file line number Diff line number Diff line change 77import type { MetaFunction } from "react-router" ;
88import {
99 cacheClientLoader ,
10+ createClientLoaderCache ,
1011 decacheClientLoader ,
1112 useCachedLoaderData ,
1213} from "remix-client-cache" ;
@@ -25,7 +26,7 @@ export const loader = async () => {
2526 return { user : { description : Math . random ( ) } } ;
2627} ;
2728
28- export const clientLoader = cacheClientLoader ;
29+ export const clientLoader = createClientLoaderCache ( ) ;
2930clientLoader . hydrate = true ;
3031
3132export const clientAction = decacheClientLoader ;
You can’t perform that action at this time.
0 commit comments