Skip to content

Commit

Permalink
takeScreenshot now returns string
Browse files Browse the repository at this point in the history
  • Loading branch information
fayeed committed Aug 1, 2020
1 parent 11494f8 commit 77088b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Example = () => {
#### `UseScreenshotReturnType`

- `isLoading` - Indicates if the screenshot is loading this is useful for some webpages that are big and have lots of content to render.
- `takeScreenshot: (types: ImgType, options: OptionsType)` - A function to take screenshot.
- `takeScreenshot: (types: ImgType, options: OptionsType): string | undefined` - A function to take screenshot.
- `image` - Contains the dataUrl for the image.
- `clear()` - Clear the image from the memory.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-screenshot-hook",
"version": "1.0.1",
"version": "1.0.2",
"description": "React hook to take screenshot for React components.",
"author": "fayeed",
"license": "MIT",
Expand Down
16 changes: 8 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ export const useScreenshot = (options?: UseScreenshotProps) => {
const takeScreenshot = useCallback(
async (type?: ImgType, options?: OptionsType) => {
setLoading(true);
let tempImage: string | undefined;

try {
let image: string;

// using body tag causes a wierd bug
const body = document.getElementById("root")!;

if (type === "jpg") {
image = await toJpeg(ref?.current || body, options);
tempImage = await toJpeg(ref?.current || body, options);
} else {
image = await toPng(ref?.current || body, options);
tempImage = await toPng(ref?.current || body, options);
}

setImage(image);
setImage(tempImage);
} catch (e) {
console.error(e);
}
} finally {
setLoading(false);

setLoading(false);
return tempImage;
}
},
[]
);
Expand Down

1 comment on commit 77088b7

@vercel
Copy link

@vercel vercel bot commented on 77088b7 Aug 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.