// The typed hook surface for the `app` api — bound ONCE, here, and imported by // every page instead of `@voltro/client`. // // `AppProcedures` is emitted by codegen into the api's `rpcGroup.generated.ts`: // a type-level map of every rpc tag to the descriptor behind it. Feeding it to // `createHooks` makes the tag a literal union and the input/output types INFER: // // const { data } = useSubscription('notes.list') // rows, typed // const create = useMutation('notes.create') // input + output typed // // So no page declares a row `interface` mirroring the api any more. The old // `useSubscription>('app', 'notes.list')` spelled the api // name at every call site, left the tag an unchecked string (a typo was a // runtime error), and the `` was an ASSERTION nothing compared against the // server. All three are compile-checked now. // // `'app'` is the key this web app gave the api in `app.config.ts` -> `apis`. // `import type` is erased, so the binding costs the browser bundle nothing. import { createHooks } from '@voltro/client' import type { AppProcedures } from '@{{projectName}}/api/rpcGroup' // Destructured on purpose - `react-hooks/rules-of-hooks` only treats a member // call as a hook when the object is PascalCase, so top-level `useX` identifiers // are what keep the React lint rules working at every call site. export const { useSubscription, useMutation, useAction } = createHooks('app')