Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

react-detect-print

React higher-order component (HOC) to detect when a page is being printed.

What

Use as a HOC to receive a printing prop, which will be true if the page is being printed and false otherwise.

Example

import React from "react";
import ReactDOM from "react-dom";
import detectPrint from "react-detect-print";

const App = props => <div>Printing? {JSON.stringify(props.printing)}</div>;

const EnhancedApp = detectPrint(App);

ReactDOM.render(<EnhancedApp />, document.getElementById("..."));

See react-detect-print-example for a more in-depth example.

Should I use this?

The general recommendation is to use media queries instead. For those times when that won't work, this may fit the bill. However, it has not been widely tested so use at your own risk. It was adapted using approach detailed in this blog post.

Installation

npm install --save react-detect-print

Credits

Adopted from post by TJ VanToll.

You can’t perform that action at this time.