Skip to main content
API Reference / modelence / client / createClientModule
createClientModule<TModule>(moduleName): object
Defined in: packages/modelence/src/client/module.ts:88 Creates a typed client accessor for a module’s public configs, queries, and mutations. Use import type to reference the module so no server code is bundled on the client. Arg and return types for queries and mutations are inferred automatically from the server-side handler signatures.

Example

// src/client/payments.ts
import type paymentsModule from '../server/payments';
import { createClientModule } from 'modelence/client';

export const payments = createClientModule<typeof paymentsModule>('payments');
// src/components/Checkout.tsx
import { useQuery, useMutation } from '@tanstack/react-query';
import { payments } from '../client/payments';

// Typed config — public keys only, private and secret keys excluded:
const currency = payments.getConfig('currency'); // string | undefined

// Typed query — pass directly to useQuery:
const { data: products } = useQuery(payments.query('getProducts', { page: 1 }));

// Typed mutation — pass directly to useMutation:
const { mutate: charge } = useMutation(payments.mutation('charge'));
charge({ amount: 100 }); // args typed from handler signature

Type Parameters

Type Parameter
TModule extends AnyModule

Parameters

ParameterTypeDescription
moduleNamestringThe module’s name as passed to new Module(name, ...).

Returns

NameTypeDescriptionDefined in
getConfig()(key) => undefined | PublicKeyOf<TModule["configSchema"]>[K]-packages/modelence/src/client/module.ts:90
infiniteQuery()(name, getArgs) => objectReturns options for useInfiniteQuery. The getArgs callback receives the current pageParam and returns the args to pass to the query handler. Spread the result into useInfiniteQuery alongside getNextPageParam. Annotate the pageParam type in the callback so TypeScript can infer the page param type — no manual generic needed on useInfiniteQuery.packages/modelence/src/client/module.ts:134
mutation()(name) => object-packages/modelence/src/client/module.ts:114
query()(name, …rest) => object-packages/modelence/src/client/module.ts:97