Skip to content

Hooks

PowerPointViewer is a thin forwardRef orchestrator. Almost all of its logic lives in 67+ custom hooks composed inside PowerPointViewer.tsx, while the visual components are largely presentational. State is held entirely in React hooks - there is no external state library.

Internal vs public

Most of these hooks are internal architecture: they assume a specific composition order and shared inputs, and are not importable from the package. A curated subset is exported from the pptx-viewer/viewer entry for advanced integrations. The tables below mark which is which.

Architecture (internal)

These hooks describe how the viewer is wired. They are named in the source and the README but are not part of the supported public import surface - treat them as conceptual reference.

HookConcern
useViewerStateComposite state hook (composes core + UI state).
useViewerCoreStateDocument state: slides, selection, canvas size, mode.
useViewerUIStateUI state: panel visibility, dialog flags, toolbar flags.
useDerivedSlideStateComputed visible indexes, sections, master pseudo-slide.
useEditorHistoryUndo/redo snapshot stack with deferred capture during pointer interactions.
useZoomViewportZoom level, fit-to-width, viewport DOM ref.
useEditorOperationsComposes all editor operations into one result.
useLoadContentParses the PPTX buffer on mount via PptxHandler.
useContentLifecycleContent sync, dirty tracking, recovery detection.
usePresentationModeSlideshow navigation, animation, transitions.
useExportHandlersPNG / SVG / PDF / GIF / video / PPTX export logic.
usePrintHandlersPrint dialog and layout.
useInsertElementsShape / image / text box / table / chart insertion.
useElementManipulationMove / resize / rotate / delete elements.
useSlideManagementAdd / delete / duplicate / reorder / hide slides.
useTableOperationsRow/column insert/delete, merge/split cells.
usePointerHandlersMouse/touch event processing for the canvas.
useKeyboardShortcutsHotkey definitions.
useViewerIntegrationTop-level integration: I/O, export, print, pointers, lifecycle.

There are dozens more (clipboard, comments, sections, autosave, font injection, recovery, theme handlers, presentation sub-hooks, etc.). The complete list is in the package README's Hooks Reference.

Public hooks

The following are exported from pptx-viewer/viewer and are safe to import. They are opt-in and tree-shakeable. Note these come from the /viewer entry - the root pptx-viewer entry exports only the component, renderToCanvas, and theme utilities.

tsx
import { useThemeSwitching, useCollaborativeState } from 'pptx-react-viewer/viewer';

Collaboration hooks

For building custom collaboration UIs or driving sync yourself. See Collaboration. Require the yjs / y-websocket optional peers.

HookExported type(s)Purpose
useYjsProvider-Manages the Yjs WebSocket provider lifecycle.
usePresenceTrackingUsePresenceTrackingInput, UsePresenceTrackingResultTracks remote cursors, selection, and connection status.
useCollaborativeStateUseCollaborativeStateInputCRDT-backed shared document state.
useCollaborativeHistoryUseCollaborativeHistoryInput, UseCollaborativeHistoryResultCollaborative undo/redo.

The CollaborationProvider component and presence UI (RemoteUserCursors, UserAvatarBar, CollaborationStatusIndicator) are exported alongside these.

Theme switching

HookExported type(s)Purpose
useThemeSwitchingUseThemeSwitchingInput, ThemeSwitchingResultSwitch the document's PowerPoint theme.

Audience-window helpers

Not hooks, but exported from pptx-viewer/viewer for the presenter/audience-window flow: isAudienceTab, loadAudienceContent, storeAudienceContent, clearAudienceContent.

Hooks reference table caveat

The package README publishes a large "Hooks Reference" table listing ~40 hooks. Most of those are internal composition hooks and are not importable - only the hooks listed under Public hooks above are re-exported from pptx-viewer/viewer. Do not import internal hooks from deep paths; they have no stability guarantees.

For the broader internal hook map, see Overview and the package README.

Released under the Apache-2.0 License.