react-component-print
Version:
**Easily print specific HTML content in your React applications.** This lightweight library allows you to wrap components in a printable container and trigger printing programmatically using a custom event.
65 lines (44 loc) • 1.19 kB
Markdown
# 📄 react-html-print
**Easily print specific HTML content in your React applications.**
This lightweight library allows you to wrap components in a printable container and trigger printing programmatically using a custom event.
## ✨ Features
- Programmatic printing using `CustomPrintEvent`
- Simple integration and minimal dependencies
## 📦 Installation
```bash
npm install react-html-print
```
## 🚀 Usage
### 1. Wrap content with `<Printable>`
```tsx
import { Printable } from "react-component-print";
function MyComponent() {
return (
<Printable>
<div>
<h1>This content will be printed</h1>
<p>Only what's inside Printable will show in the print view.</p>
</div>
</Printable>
);
}
```
### 2. Trigger print with `PrintHtml`
```tsx
import { PrintHtml } from "react-component-print";
function PrintButton() {
return (
<button onClick={() => PrintHtml() }>
Print Now
</button>
);
}
```
✅ This dispatches a custom event, which causes component listening via `Printable` to call `window.print()`.
## 📃 License
MIT