该插件将会把页面的内容完整的打印出来,保证打印样式跟页面样式统一。
npm install --save react-to-print
import ReactToPrint from 'react-to-print';
//触发按钮
const componentRef = useRef()
<div>
<ReactToPrint
trigger={() => <a href="#">打印</a>}
content={() => componentRef.current}
/>
//打印内容
<div ref={componentRef }>
xxxxxxxx
<div/>
</div>