print-react
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

print-react 🖨️

Version

Lightweight component wrapper to print the wrapped component when desired

Highlights

  • print individual react component(s)
  • lightweight
  • fully written in TypeScript

Install

npm install --save print-react

Or if you use Yarn:

yarn add print-react

Usage

Detailed documentation coming soon. An example usage would be:

import { Print } from "print-react";

export const MyExampleParentComponent = () => {
  const ref = useRef<{ openPrintDialog: () => Promise<void> }>();

  // use the following line only if you need to 'react' to the dialog state change:
  const [printDialogOpen, setPrintDialogOpen] = useState(false);

  return (
    <div>
      <Print
        ref={ref}
        printWidth={420}
        marginTop={48}
        marginLeft={64}
        onOpenPrintDialog={() => {
          setPrintDialogOpen(true);
        }}
        onClosePrintDialog={() => {
          setPrintDialogOpen(false);
        }}
      >
        <MyComponentIWantToPrint />
      </Print>
      <button
        onClick={async () => {
          await ref.current.openPrintDialog();
        }}
      >
        Click to print!
      </button>
    </div>
  );
};

Package Sidebar

Install

npm i print-react

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

12.8 kB

Total Files

7

Last publish

Collaborators

  • maks-io