QueryClientFactory
katanakit-js / QueryClientFactory
Class: QueryClientFactory
Section titled “Class: QueryClientFactory”Defined in: core/services/query.service.ts:36
QueryClientFactory - Factory Pattern para crear instancias de QueryClient.
Centraliza la creación de clientes: create() fabrica un cliente nuevo
(por petición en SSR) y createShared() reemplaza el singleton compartido.
El resto del código no llama new QueryClient() directamente, así que la
política de creación vive en un único punto (Open/Closed).
Example
Section titled “Example”// SSR: un cliente por peticiónconst client = QueryClientFactory.create({ defaultOptions: { queries: { staleTime: 60_000 } } });
// Browser: singleton compartidoQueryClientFactory.createShared();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new QueryClientFactory(): QueryClientFactory;Returns
Section titled “Returns”QueryClientFactory
Methods
Section titled “Methods”create()
Section titled “create()”static create(config?): QueryClient;Defined in: core/services/query.service.ts:50
Fabrica un nuevo QueryClient. Úsalo en el servidor (SSR) para obtener un cliente por petición y evitar compartir la caché global.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config? |
QueryClientConfig |
TanStack QueryClientConfig (caches, default options). |
Returns
Section titled “Returns”QueryClient
Un QueryClient fresco.
Example
Section titled “Example”const client = QueryClientFactory.create();await client.prefetchQuery({ queryKey, queryFn });createShared()
Section titled “createShared()”static createShared(config?): QueryClient;Defined in: core/services/query.service.ts:61
Reemplaza el singleton compartido con un cliente configurado. Limpia la caché del cliente anterior antes de intercambiarlo.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config? |
QueryClientConfig |
TanStack QueryClientConfig. |
Returns
Section titled “Returns”QueryClient
El nuevo QueryClient compartido.