I have a Home
component that renders with a map
function an array of contact
s, each contact
has its own print button and should print only its contact . The issue is that currently it prints the entire page and not just the contact
which the print was clicked on.
I added a isPrinting
state to the contact
component, by default set to false
, when the print button is being clicked it's being set to true
and when the print dialog is being closed I set it back to false.
How can I actually make the print button to print only the contact that its print was click?
My handlePrint
function on contact
component:
handlePrint = () => {
this.setState({ isPrinting: true });
window.print();
window.onafterprint(
this.setState({ isPrinting: false })
);
};
map
function on Home
component:
contacts.map(info => (
<SearchResultsPanel
info={info}
key={info.id}
/>
I'm using '@media print'
to control the print styles.