React-to-print: I can not use CSS in print page

Created on 17 Dec 2019  路  5Comments  路  Source: gregnb/react-to-print

Hi!
I dont know if I am doing something wrong with this.
I am using TypeScript in a SharePoint context.
myComponent to be printed has it owns css (as _name_.module.scss). If I render the component in the render of React works fine, but when I use the ref into the myComponent losses its styles.
Someone can help me?

Most helpful comment

Does not exist any problem. Set prop copyStyles = true to maintain styles from component itself

All 5 comments

<ReactToPrint
  trigger={() => <p>Printer Fn </p>}
  content={() => this.testTitleRef1.current}
  copyStyles={false}
  onBeforeGetContent={()=> this.onBeforeGetContent()}
  onBeforePrint={() => this.onBeforePrint()}
  onAfterPrint={() => this.onAfterPrint()}
  onPrintError={(el, e) => this.onPrintError(el, e)}
/>

// the component to print (a functional component)
<div ref={props.refComp} className={styles["body-page"]}>
  <h1>{props.count}</h1>
  <p className={styles["text"]}>Texto</p>
</div>;

Hello. Can you please post a working (codesandbox or equivalent) code example so we can see exactly what the problem is? Thank you

Yes of course
https://codesandbox.io/s/friendly-davinci-pdpn3?fontsize=14&hidenavigation=1&theme=dark

another question. Where I can find the full documentation of the reacto-to-print

UPDATE:
I realized that the problem is the " copyStyles={true}" accessory.
My apologies.

I updated the codeSandBox for Class component and Functional component
Great module!

Does not exist any problem. Set prop copyStyles = true to maintain styles from component itself

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hoangdoan267 picture hoangdoan267  路  8Comments

jogoool picture jogoool  路  8Comments

JoshuaKGoldberg picture JoshuaKGoldberg  路  3Comments

sprietNathanael picture sprietNathanael  路  4Comments

jermsam picture jermsam  路  7Comments