How to print React component on click of a button?

前端 未结 8 2081
执念已碎
执念已碎 2020-12-03 01:42

How can I print only one component on click of a button.

I know this solution:

window.frames[\"print_frame\"].window.focus();
window.frames[\"print         


        
8条回答
  •  孤街浪徒
    2020-12-03 02:16

    I was looking for a simple package that would do this very same task and did not find anything so I created https://github.com/gregnb/react-to-print

    You can use it like so:

      Print this out!}
       content={() => this.componentRef}
     />
      (this.componentRef = el)} />
    

提交回复
热议问题