Skip to content

[Feature Request] Support dynamic documentTitle via function callback #832

@Henry-G-H-Huang

Description

@Henry-G-H-Huang

Problem

Currently, documentTitle is captured at hook initialization time, making it impossible to set dynamic filenames (e.g., with timestamps) without recreating the hook.

Use Case

Users need to include timestamps or other dynamic data in the print filename:

  • Invoice with current date: Invoice_2026-02-02.pdf
  • Report with generation time: Report_14-30-25.pdf
  • B/L draft with timestamp: BILL_OF_LADING_DRAFT_2026-02-02_09-30.pdf

Current Workaround

Users must either:

  1. Accept static filenames (loses timestamp info)
  2. Recreate the hook on every state change (performance issue)
  3. Violate React Hooks rules by conditionally calling hooks

Proposed Solution

Support function callbacks for documentTitle:
// Option 1: Allow function type
documentTitle?: string | (() => string);

// Option 2: Add new parameter
getDocumentTitle?: () => string;

Implementation
I'm willing to submit a PR for this feature. Would the maintainers be open to:

  • Option 1 (extend existing parameter)
  • Option 2 (add new parameter)
  • Alternative approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions