Create Bundle
pluv.io ships @pluv/react to leverage @pluv/client in a type-safe and React.js way.
Create a PluvIO instance
First, create a PluvIO
instance from the @pluv/io
package in your backend codebase.
1// backend/io.ts23import { createIO } from "@pluv/io";4import { platformNode } from "@pluv/platform-node";56export const io = createIO({ platform: platformNode() });78// Export the websocket client io type, instead of the client itself9export type AppPluvIO = typeof io;
Create a Pluv React bundle
Then, import your PluvIO
type to the frontend, and create your type-safe React.js bundle using @pluv/react
.
1// frontend/io.ts23import { createBundle, createClient } from "@pluv/react";4import { z } from "zod";5// import your PluvIO instance from your backend codebase6import { type AppPluvIO } from "backend/io";78const client = clientClient<AppPluvIO>({9 authEndpoint: () => "{{your auth endpoint}}",10 wsEndpoint: () => "{{your ws endpoint}}",11});1213export const {14 // factories15 createRoomBundle,1617 // components18 PluvProvider,1920 // hooks21 usePluvClient,22} = createBundle(client);2324export const {25 // components26 PluvRoomProvider,2728 // hooks29 usePluvBroadcast,30 usePluvConnection,31 usePluvEvent,32 usePluvMyPresence,33 usePluvMyself,34 usePluvOther,35 usePluvOthers,36 usePluvRoom,37 usePluvStorage,38} = createRoomBundle();