Skip to content

Commit 52d39ab

Browse files
committed
docs(react-start): serialization adapters
1 parent 97afc67 commit 52d39ab

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/start/framework/react/guide/server-functions.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@ export default defineConfig({
270270
})
271271
```
272272

273+
### Custom serialization adapters
274+
275+
You can create custom serialization adapters to handle complex types that can't be serialized by default.
276+
277+
Example:
278+
279+
```ts
280+
// src/start.ts
281+
import { createStart } from "@tanstack/react-start";
282+
import { createSerializationAdapter } from "@tanstack/react-router";
283+
284+
const bigIntAdapter = createSerializationAdapter({
285+
key: "bigint",
286+
test: (value: unknown): value is bigint => typeof value === "bigint",
287+
toSerializable: (bigInt) => bigInt.toString(),
288+
fromSerializable: (value) => BigInt(value),
289+
});
290+
291+
export const startInstance = createStart(() => {
292+
return {
293+
serializationAdapters: [bigIntAdapter],
294+
};
295+
});
296+
```
297+
273298
---
274299

275300
> **Note**: Server functions use a compilation process that extracts server code from client bundles while maintaining seamless calling patterns. On the client, calls become `fetch` requests to the server.

0 commit comments

Comments
 (0)