useDocumentRevision
Returns the revision of the current document state and re-renders the component when it changes, such as for an "unsaved changes" indicator or reacting to any document change. Returns undefined while no document is loaded.
const revision = useDocumentRevision()The revision is an opaque string: compare it with an earlier revision, and don't read anything into its content.
Behavior
- Every edit by the local user changes the revision, including the edits that merge into one undo step.
- Undo and redo return the revision to the value it had at that point of the history. Equal revisions mean that no edits were made in between, or that all of them were undone.
- Changes applied with
excludeFromHistory(see useSetWidgetProps) don't change the revision. - A revision is meaningful only for the document it was read from: useResetPdf and useLoadPdf start a new history.
To read the revision in an event handler without re-rendering, use useDocumentRevisionGetter. To run code on every document change, put the revision in the dependencies of a useEffect.
Example
import { useDocumentRevision } from '@sdk-pdf/react'
// `savedRevision` is the revision read when the document was loaded or last saved.
function UnsavedChangesBadge({ savedRevision }: { savedRevision: string | undefined }) {
const revision = useDocumentRevision()
return revision !== savedRevision ? <span>Unsaved changes</span> : null
}For a complete save flow, see useDocumentRevisionGetter.
See also useUndoRedo and useDocumentSaving.