
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-component-screenshot
Advanced tools
Effortlessly capture and save high-quality screenshots of your React components with this lightweight tool.
React component to take screenshot of the component.
Screenshot
component.npm install react-component-screenshot
Peer dependencies: react
, html2canvas
.
npm install react html2canvas --save
Wrap your component with ScreenShot
component and pass the controller
prop.
import { ScreenShotController, ScreenShot } from 'react-component-screenshot';
export function Example() {
// Create a controller
const controller = new ScreenShotController();
const takeCapture = () => {
// Capture and save the screenshot
controller.captureAndSave({
name: 'my-awesome-component',
extension: 'jpg',
type: 'image/jpeg',
quality: 1
});
};
// Wrap your component with ScreenShot component and pass the controller
return (
<ScreenShot controller={controller}>
<div className="flex flex-col gap-2">
<h1>My awesome Component</h1>
<p>Some content</p>
<button onClick={takeCapture}>take Capture</button>
</div>
</ScreenShot>
);
}
If you prefer to obtain the image as a base64 string, it's also very easy. š Just follow this example:
import { ScreenShotController, ScreenShot } from 'react-component-screenshot';
export function Example() {
// Create a controller
const controller = new ScreenShotController();
const takeCapture = () => {
// Capture and get the screenshot as base64 string
controller.capture().then((base64) => {
console.log(base64);
});
};
...
}
š¼ļø Capture Components Not in the DOM
Need to capture a component that's not in the DOM? No problem! š (Obviusly You don't even need to use the ScreenShot component for this.)
import { ScreenShotController, ScreenShot } from 'react-component-screenshot';
export function Example() {
// Create a controller
const controller = new ScreenShotController();
const takeCapture = () => {
// Capture and save the screenshot
controller.captureAndSaveFromComponent({
component: (
<div>
<h1>My awesome component</h1>
<p>Some content</p>
</div>
),
name: "my-awesome-component",
extension: "png",
type: "image/png",
quality: 1,
});
};
...
}
Contributions are welcome. If you find an issue or have an idea to improve react-component-screenshot, feel free to open an issue or submit a pull request. š
Licensed as MIT open source. š
FAQs
Effortlessly capture and save high-quality screenshots of your React components with this lightweight tool.
The npm package react-component-screenshot receives a total of 8 weekly downloads. As such, react-component-screenshot popularity was classified as not popular.
We found that react-component-screenshot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.