@quark-fw/store
v0.1.15
Published
Isomorphic store and tRPC client hooks for the Quark framework
Readme
@quark-fw/store
Isomorphic store and tRPC client hooks for React apps built on the Quark framework. Works during SSR and in the browser.
Install
npm i @quark-fw/storereact is a peer dependency.
Usage
import Store, { useStore, useTrpc, StoreContext } from "@quark-fw/store";
// on the server / app entry: create a Store around your tRPC client and provide it
const store = new Store({ trpcClient });
// <StoreContext.Provider value={store}>...</StoreContext.Provider>
function TodoList() {
const trpc = useTrpc(); // typed tRPC client (AppRouter comes from your app)
const store = useStore(); // shared values/promises, survives SSR serialization
// ...
}Also exported:
createTinyRPCClient— minimal tRPC client factory used byuseTrpcjsonSafeFetch— fetch wrapper that reports JSON errors through the shared error channel@quark-fw/store/src/errors.js—reportError/errorMessagehelpers@quark-fw/store/src/serialize.js— SSR-safe serialization (Serializetype)@quark-fw/store/src/usePromise.js— suspense-style promise hook
Part of the Quark framework.
