liwi-resources-void-client
v14.0.0
Published
void client implementation for liwi
Readme
About
No-op TransportClient. It satisfies the interface so a provider tree can be built, but never talks to a server: send and subscribe throw.
Its purpose is server-side rendering — render the shell with no data on the server, then let a real transport take over on the client after hydration.
Install
npm install --save liwi-resources-void-clientUsage
import { createVoidTransportClient } from "liwi-resources-void-client";
import { createWebsocketTransportClient } from "liwi-resources-websocket-client";
import type { WebsocketTransportClientOptions } from "liwi-resources-websocket-client";
import { TransportClientProvider } from "react-liwi";
export function App() {
return (
<TransportClientProvider<WebsocketTransportClientOptions>
url="ws://localhost:4005/ws"
createFn={
globalThis.window === undefined
? createVoidTransportClient
: createWebsocketTransportClient
}
onError={console.error}
>
<Home />
</TransportClientProvider>
);
}Components must therefore render something for the loading state (initialLoading in react-liwi); that is what the server emits.
API
createVoidTransportClient()
Returns a TransportClient where connect, close and listenStateChange are no-ops, and send / subscribe throw Void client: send should not be called / Void client: subscribe should not be called.
Reaching one of those throws means a component tried to fetch during SSR. Guard the call site (skip the query on the server) rather than catching the error.
