react-to-print
Advanced tools
Changelog
2.10.0 (August 23rd, 2020)
print
has been added. This can be used to override the default browser Window.print
. This can be useful if you want to print in an alternative environment such as Electron. As part of this change, onPrintError
will now report if an error occurs in a passed in print
method. Thanks to Ririshi for this ideadevDependencies
, npm dedupe
, npm audit fix
Changelog
2.8.0 (May 19th, 2020)
FEATURE 245: documentTitle
prop can now be passed to set a default filename when the user is saving as a PDF. Thanks zb2oby
FEATURE 244: trigger
is now an optional prop. To print without it we now offer two new options.
PrintContextConsumer
with a render-props pattern:
import { PrintContextConsumer } from 'react-to-print';
<ReactToPrint content={() => this.componentRef}>
<PrintContextConsumer>
{({ handlePrint }) => <button onClick={handlePrint}>Print this out!</button>}
</PrintContextConsumer>
</ReactToPrint>
useReactToPrint
for hook-based printing
import { useReactToPrint } from 'react-to-print';
const Example = () => {
const componentRef = useRef();
const handlePrint = useReactToPrint({ content: () => componentRef.current });
return (
<div>
<ComponentToPrint ref={componentRef} />
<button onClick={handlePrint}>Print this out!</button>
</div>
);
};
Huge thanks to vtsybulin for these fantastic additions.
CHORE: upgrade devDependencies
to latest
Changelog
2.7.0 (May 1st, 2020)
pageStyle
prop can now be passed as a function. Thanks sergeyshmakovtarget.contentWindow.print
devDependencies
to latestbrowserslist
best practices