Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
usescreenshot-react
Advanced tools
#usescreenshot-react
React hook allows you to take "screenshots" of webpages or parts of it
Using npm
npm install --save usescreenshot-react
import React, {useRef} from "react";
import {useScreenshot} from 'usescreenshot-react';
const Example = () => {
const {image, takeScreenshot, isLoading, isError} = useScreenshot();
const ref = useRef<HTMLDivElement>(null);
return isLoading ? (
<div>Loading...</div>
) : (
<div>
{isError && <p>Error</p>}
<div ref={ref}/>
<h1>Capture Me</h1>
{image && <img src={image} alt={'Screenshot'}/>}
<button onClick={() => takeScreenshot(ref.current)}>Take screenshot</button>
</div>
);
}
or
import React, {useRef} from "react";
import {useScreenshot} from 'usescreenshot-react';
const Example = () => {
const {takeScreenshot, isLoading, isError} = useScreenshot();
const ref = useRef<HTMLDivElement>(null);
const getImage = () => {
takeScreenshot(ref.current, {
backgroundColor: null,
logging: false,
scale: 2
}).then(image => console.log(image));
}
return isLoading ? (
<div>Loading...</div>
) : (
<div>
{isError && <p>Error</p>}
<div ref={ref}>
<h1>Capture Me</h1>
</div>
<button onClick={getImage}>Take screenshot</button>
</div>
);
}
createFileName(extension: string, name?: string): string
- return file name. If the name is not specified, then the current date is returned
useScreenshot(type?: string, quality?: number)
type
- String indicating the image format. The default format type is image/pngquality
- A number between 0 and 1The use useScreenshot
hook returns an object containing the following properties:
image: string | undefined
- Screenshot in base64 formattakeScreenshot = (captureRef: HTMLElement | null, options?: Partial<Options> | undefined) => Promise<string | undefined>
- Function for creating screenshot from html node and return screenshotisLoading: boolean
- Indicates if the screenshot is loadingisError: boolean
- Indicates whether an error occurred during screenshot loadingclear = (): void
- Clear screenshot stringtakeScreenshot(captureRef: HTMLElement | null, options?: Partial<Options>)
captureRef
- Ref to the HTMLElement for which to for which the screenshot should be takenoptions
- configuration html2canvas options to take a screenshotMIT © n0mver
FAQs
React hook allows you to take screenshots of webpages or parts of it
The npm package usescreenshot-react receives a total of 3 weekly downloads. As such, usescreenshot-react popularity was classified as not popular.
We found that usescreenshot-react 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.