I don't know if it is in the scope of this library, but I think it could be very nice to have such callback. For example, I have some collection of data and. For each item I have a button "Print Invoice". It would be very nice to update "Printable" component data instead of render it for each item.
Something like this:
static propTypes = {
/* Copy styles over into print window. default: true */
copyStyles: PropTypes.bool,
/* Trigger action used to open browser print /
trigger: PropTypes.func.isRequired,
/* Content to be printed /
content: PropTypes.func.isRequired,
/* if you need to do something with the data for printable component
right before the print */
onBeforePrint: PropTypes.func,
};
static defaultProps = {
copyStyles: true,
onBeforePrint: () => {},
};
...
handlePrint = () => {
const {
content,
copyStyles,
onBeforePrint,
} = this.props;
onBeforePrint();
let printWindow = window.open("", "Print", "status=no, toolbar=no, scrollbars=yes", "false");
...
}
I haven't checked it yet and I'm not sure if it's necessary for this library.
Sorry for every day comments here :) I have a project where I'll need to print a lot of data and while I researched print-connected libraries for React, I've found your library potentially the most useful for this project.
I think this is a great idea but let's also add one after printing so:
onBeforePrint
onAfterPrint
I'm going to take this one up because the afterPrint is a little bit of work but I'm interested in this one :)
Ok this is now complete in 1.1.12
I am wondering if the onBeforePrint function can be used to run print if it returns true, and stop printing if it returns false? Thank you.
Most helpful comment
I am wondering if the onBeforePrint function can be used to run print if it returns true, and stop printing if it returns false? Thank you.