React-to-print: add onBeforePrint callback

Created on 30 Mar 2018  路  4Comments  路  Source: gregnb/react-to-print

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.

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

invious picture invious  路  4Comments

k-jiang picture k-jiang  路  5Comments

quadh picture quadh  路  5Comments

hoangdoan267 picture hoangdoan267  路  8Comments

AJTJ picture AJTJ  路  4Comments