> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Frameworks and runtimes

> Use the client from Next.js, React Native, Vue, Svelte, TanStack, Node.js, Bun and plain browser modules

Bijection ships two client entries: `bijection/client`, which runs anywhere
JavaScript with streaming `fetch` runs, and `bijection/react`. Every
framework uses one of them. Type the client from the app tree with a
type-only import, as in [the client](https://docs.bijection.com/clients/javascript.md).

## React frameworks

**Next.js, Remix and TanStack Start.** Live views are client components: make
the client in a client module and use the [React hooks](https://docs.bijection.com/clients/react)
under `<Bijection client>`. A server-rendered value is one `client.query` in
the request, on a client made for that request with the signed-in person's
token:

```tsx app/notes/page.tsx theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { api, connect } from "@bijectionhq/bijection/client";
import type App from "../../bijection/app";

export default async function NotesPage() {
  const client = connect(process.env.BIJECTION_URL!, { contract: "discover", token: await sessionToken() });
  const listed = await client.query(api<typeof App>().notes.recentNotes);
  await client.close();
  if (!listed.ok) return <p role="alert">{listed.message}</p>;
  return <ul>{listed.value.map((note) => <li key={note.id}>{note.text}</li>)}</ul>;
}
```

Keep a server client scoped to its request: a client carries one identity.

**React Native and Expo.** Use `bijection/react` as on the web. The client
needs a streaming `fetch` and `Temporal`. Install a `Temporal` polyfill
where the runtime has none.

**TanStack Query.** A one-off read fits a query function. Throw on a refusal
so TanStack Query reports it, and include every argument in the cache key:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const notes = useQuery({
  queryKey: ["notes.recentNotes"],
  queryFn: async () => {
    const listed = await client.query(api<typeof App>().notes.recentNotes);
    if (!listed.ok) throw new Error(listed.message);
    return listed.value;
  },
});
```

For live values, use `useWatch` rather than polling.

## Vue, Nuxt, Svelte and SvelteKit

There is no binding for these frameworks: use `client.watch` and stop it when
the component goes away.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// Svelte 5
let notes = $state<Note[]>([]);
onMount(() => {
  const live = client.watch(api<typeof App>().notes.recentNotes);
  void (async () => {
    for await (const listed of live) if (listed.ok) notes = [...listed.value];
  })();
  return () => live.stop();
});
```

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// Vue 3
const notes = ref<Note[]>([]);
const live = client.watch(api<typeof App>().notes.recentNotes);
onMounted(async () => {
  for await (const listed of live) if (listed.ok) notes.value = [...listed.value];
});
onUnmounted(() => live.stop());
```

`Note` is `FactOf<typeof items>` from the app's notes table, `notes.items`. In Nuxt and
SvelteKit, make the client on the browser only, and server-render with a
per-request `client.query` as for Next.js. Pass an auth adapter as `token`
when people sign in; see [Connect and authenticate](https://docs.bijection.com/clients/react/configuration.md).

## Node.js, Bun and Deno

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { api, connect } from "@bijectionhq/bijection/client";
import type App from "./bijection/app";

const token = process.env.BIJECTION_TOKEN;
const client = connect(process.env.BIJECTION_URL!, { contract: "discover", ...(token === undefined ? {} : { token }) });
const added = await client.mutate(api<typeof App>().notes.add, { text: "From a script" });
console.log(added.ok ? added.value : `${added.code}: ${added.message}`);
await client.close();
```

Close the client when the script is done, or the live connection keeps the
process running.

## A plain browser module

A page can load the client as an ES module through a tool that resolves
package exports, such as the Vite dev server of the
[starter](https://docs.bijection.com/start/quickstart.md):

```ts src/main.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { api, connect } from "@bijectionhq/bijection/client";
import type App from "../bijection/app";

const client = connect(import.meta.env.VITE_BIJECTION_URL, { contract: "discover" });
const items = document.querySelector("ul")!;

void (async () => {
  for await (const listed of client.watch(api<typeof App>().notes.recentNotes)) {
    if (!listed.ok) continue;
    items.replaceChildren(...listed.value.map((note) => Object.assign(document.createElement("li"), { textContent: note.text })));
  }
})();
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.