react-to-print
Advanced tools
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