@genomdev/react
React bindings for the Genom viewer
15 exported symbols across 1 entry point
@genomdev/react
Classes
Functions
Creates a viewer mounted into the given element.
Binds a {@link Viewer} to a React component's lifecycle. State is read through `useSyncExternalStore`: the viewer is the external source of truth, and subscribing to it directly avoids duplicating state in `useState` and avoids tearing under concurrent rendering.
Subscribes to one viewer event for the life of the component. The handler is kept in a ref, so a component that declares it inline — which is every component — does not resubscribe on every render.
Interfaces
A format: everything one file type needs, in one value. `@genomdev/docx` exports one of these for Word, covering both generations. Nothing else has to know that `.doc` exists.
A format that has not been loaded yet. The descriptor carries the recognition rules, so the registry can decide whether this is the module it needs before paying for it. `load` resolves to the module itself, which in a bundler is a chunk of its own.
One bus, named events, typed payloads. What this replaces: a callback per format, declared in that format's options. `onSelectionChange` existed only for workbooks, nothing equivalent existed for slides, and every framework wrapper had to know which formats had which callbacks. A wrapper subscribing to one bus is the same size whatever the formats are, which is why Angular and Vue cost a hundred lines each. Format-specific events keep their format as a prefix — `sheet:select`, `slide:change` — so a name says where it came from and two formats cannot collide.
An extension that gets the viewer itself. Returns its own teardown.
Type aliases
Either an already-loaded format or a promise of one.
The viewer: bytes in, a document on the screen, and a way to reach it after. The one place that knows the whole path — recognise, load the module, open, mount. The React, Vue and Angular wrappers are adapters over this class, so their behaviour is identical by construction rather than by convention. Three things here are the API rather than the implementation. **Formats are values.** `formats: [docx, pdf]` — eager modules or lazy descriptors, mixed freely. Nothing is registered globally, nothing is discovered, and an application that shows PDFs ships no Word parser. **Options are addressed by format.** `options: { xlsx: { formulaBar: false } }` rather than one flat bag whose keys collide the moment two formats want the same word. **Everything reports through one bus.** `viewer.on('page:change', …)`, and the format-specific events carry their format in the name. Extension has two levels, and the cheap one comes first: `decorate` changes an element a renderer already produced, which survives the renderer being rewritten; `plugins` get the viewer itself, for what nobody anticipated.
Values
The previous name of {@link useViewer}.