6.0 KiB
6.0 KiB
@suaveplan/react-packer - React 19 companion for @suaveplan/packer-browser — usePackedResource, usePackedImage, usePackedAudio, usePackedVideo, usePackedFont hooks plus PackedResourceProvider context. Consumes a real PackedResourceManager; React is a peer dep so non-React consumers never pay the cost.
React 19 companion for @suaveplan/packer-browser. Ships
usePackedResource, usePackedImage, usePackedAudio,
usePackedVideo, and usePackedFont hooks plus a
PackedResourceProvider context, so applications can consume packed
asset archives from React components without @suaveplan/packer-browser
having to ship React as a runtime dep.
Documentation tree
- error-codes — Defines the canonical error-code registry and concrete error class for the React-tier packer companion. Every failure m…
- error-codes — Defines the canonical error-code registry and concrete error class for the React-tier packer companion. Every failure m…
- use-packed-audio —
usePackedAudiois the audio analogue ofusePackedImage. It binds a packed audio asset URL to a React component's li…- use-packed-audio —
usePackedAudiois the audio analogue ofusePackedImage. It binds a packed audio asset URL to a React component's li…
- use-packed-audio —
- use-packed-font —
usePackedFontloads a packed font asset and registers it with the document so subsequent rules referencing the suppli…- use-packed-font —
usePackedFontloads a packed font asset and registers it with the document so subsequent rules referencing the suppli…
- use-packed-font —
- use-packed-image —
usePackedImageis a thin wrapper aroundusePackedResourcethat pre-fills sensible defaults for image assets: cachin…- use-packed-image —
usePackedImageis a thin wrapper aroundusePackedResourcethat pre-fills sensible defaults for image assets: cachin…
- use-packed-image —
- use-packed-resource —
usePackedResourceis the foundation hook of@suaveplan/react-packer. It binds a packed-archive virtual URL (e.g. `/…- use-packed-resource —
usePackedResourceis the foundation hook of@suaveplan/react-packer. It binds a packed-archive virtual URL (e.g. `/…
- use-packed-resource —
- use-packed-video —
usePackedVideobinds a packed video asset URL to a React component's lifecycle. Unlike the image and audio variants,…- use-packed-video —
usePackedVideobinds a packed video asset URL to a React component's lifecycle. Unlike the image and audio variants,…
- use-packed-video —
- packed-resource-provider —
PackedResourceProviderlets a React tree explicitly inject aPackedResourceManagerfrom@suaveplan/packer-browser…- packed-resource-provider —
PackedResourceProviderlets a React tree explicitly inject aPackedResourceManagerfrom@suaveplan/packer-browser…
- packed-resource-provider —
Install
bun add @suaveplan/react-packer @suaveplan/packer-browser
react and react-dom (≥ 19.0.0) are peer dependencies — the package
does not bundle them.
Quick start
import { createPackedResourceManager } from "@suaveplan/packer-browser";
import { PackedResourceProvider, usePackedImage } from "@suaveplan/react-packer";
const manager = createPackedResourceManager();
function App() {
return (
<PackedResourceProvider value={{ manager }}>
<Logo />
</PackedResourceProvider>
);
}
function Logo() {
const { url, loading, error } = usePackedImage("/assets/logo.packed");
if (loading) return <div className="logo logo--loading" />;
if (error !== null) return <div className="logo logo--error" />;
return url !== null ? <img alt="logo" src={url} /> : null;
}
If you do not mount a PackedResourceProvider, hooks fall back to the
singleton at @suaveplan/packer-browser/singleton. Adopters that prefer
zero-config get a working manager for free; adopters that want explicit
lifecycle (tests, SSR, multi-tenant apps) mount a provider and skip the
singleton entirely.
Features
- Five hooks:
usePackedResource(generic),usePackedImage,usePackedAudio,usePackedVideo,usePackedFont. - React 19 context provider for explicit
PackedResourceManagerandMessageResolverinjection. AbortSignalhonored throughout — pre-aborted signals short-circuit, unmount cancels the in-flight load, and changing the packed URL aborts the previous one.- Stable error registry —
REACT_PACKER_CODES+ReactPackerErrorbranded subclass over@suaveplan/error. cleanupreleases the cached entry on unmount so the manager's LRU can evict.
Modules
src/error-codes/error-codes.mdsrc/types/react-packer.types.mdsrc/provider/packed-resource-provider/packed-resource-provider.mdsrc/hooks/use-packed-resource/use-packed-resource.mdsrc/hooks/use-packed-image/use-packed-image.mdsrc/hooks/use-packed-audio/use-packed-audio.mdsrc/hooks/use-packed-video/use-packed-video.mdsrc/hooks/use-packed-font/use-packed-font.md