import { useEffect, useRef, useState } from 'react'; import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin, useStageState } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin, useRender, useRenderEvent } from '@embedpdf/react/render'; import { cloudEngine } from '@cloudpdf/engine'; import './redraws.css'; const engine = cloudEngine(); const plugins = [stagePlugin(), renderPlugin()]; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; interface Entry { id: number; text: string; } function Redraws() { const render = useRender(); const currentPage = useStageState((state) => state.currentPage); const [entries, setEntries] = useState([]); const count = useRef(0); useRenderEvent( (render) => render.onInvalidated, ({ pages, scope, origin }) => { const what = `${pages.length === 1 ? '1 page' : `${pages.length} pages`} · ${scope}`; const from = origin ? `an edit (${origin.kind})` : 'your code'; const entry = { id: count.current++, text: `${what} · from ${from}` }; setEntries((current) => [entry, ...current].slice(0, 4)); }, ); // Redraw the first page on load, so there's something in the list. useEffect(() => render.invalidate({ pages: [0] }), [render]); // Changes whenever this page's pixels do: key your own long-lived renders on it. const epoch = currentPage ? render.getRenderEpoch(currentPage) : 0; return (
render epoch {epoch}
    {entries.map((entry) => (
  1. onInvalidated {entry.text}
  2. ))}
); } export default function App() { return ( Loading…

}> {() => }
); }