Custom renderers
Add a renderer for your own file type, or replace a built-in one, in the AnyPreview React viewer.
Renderers are lazy React components chosen by the detected kind. Add your own, or replace a built-in one, with renderers:
import { DocViewer, defaultRenderers, type RendererDefinition } from '@anypreview/react';
const gpx: RendererDefinition = {
id: 'gpx-map',
kinds: ['xml'],
test: (d) => d.ext === 'gpx',
priority: 1, // win over the built-in XML view
load: () => import('./GpxMap'), // default export: (props: RendererProps) => JSX
zoom: 'none',
search: false,
};
<DocViewer source={file} renderers={[gpx, ...defaultRenderers]} />;A renderer gets data (the bytes), detection, fileName, zoom, rotation, theme and options. It reports facts back through onInfo({ pageCount, currentPage, scale, outline, thumbnails }), and paged renderers register registerNavigation({ goTo }). domOutline and domThumbnails help renderers that draw DOM pages.
Security
How AnyPreview opens untrusted files safely, with no macros, sandboxed HTML and email, sanitised Markdown, blocked remote images and bounded decompression.
Support the project
AnyPreview is free under the MIT licence. Here is how to get help, report bugs, contribute and sponsor its development.