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

0.0.1 • Public • Published

usePrint() for React

This is a simple react hook that lets you detect print and conditionally render components based on @media print.

Installation

npm install react-use-print

# or

yarn add react-use-print

Usage

import { usePrint } from "react-use-print";

export default function App() {
  const { isPrint, print } = usePrint();

  function printNow() {
    print();
  }

  return (
    <div>
      {isPrint ? <h1>Print</h1> : <h1>Screen</h1>}

      <button onClick={printNow}>Print</button>
    </div>
  );
}

Useful links

Readme

Keywords

Package Sidebar

Install

npm i react-use-print

Weekly Downloads

13

Version

0.0.1

License

MIT

Unpacked Size

4.39 kB

Total Files

5

Last publish

Collaborators

  • geongeorge