Create a custom renderer
mainA custom renderer is a component that implements the DocRenderer interface. It must define fileTypes (an array of strings/MIME types) and a weight (number). You can also define a fileLoader to handle custom pre-fetching logic.
import React from "react";
import DocViewer from "@cyntler/react-doc-viewer";
const MyCustomPNGRenderer: DocRenderer = ({
mainState: { currentDocument },
}) => {
if (!currentDocument) return null;
return (
<div id="my-png-renderer">
<img id="png-img" src={currentDocument.fileData as string} />
</div>
);
};
MyCustomPNGRenderer.fileTypes = ["png", "image/png"];
MyCustomPNGRenderer.weight = 1;
// To use it:
<DocViewer
pluginRenderers={[MyCustomPNGRenderer]}
documents={[
// ...
]}
/>