I'm using use-react-screenshot
to take a screenshot of a specific dom element, but the image gets weird, it looks like it partially renders the dom element
I'm using the sample code in create-react-app
import logo from ./logo.svg;
import ./App.css;
import { createRef } from react;
import { useScreenshot, createFileName } from use-react-screenshot;
function App() {
const ref = createRef(null);
const [image, takeScreenShot] = useScreenshot({
type: image/jpeg,
quality: 1.0,
});
const download = (image, { name = img, extension = jpg } = {}) => {
const a = document.createElement(a);
a.href = image;
a.download = createFileName(extension, name);
a.click();
};
const downloadScreenshot = () => takeScreenShot(ref.current).then(download);
return (
<div className=App>
<header className=App-header>
<button onClick={downloadScreenshot}>
Download screenshot
</button>
<img src={logo} className=App-logo alt=logo ref={ref} />
</header>
</div>
);
}
export default App;
A sandbox to play around with it
I'm not sure if it's related to html2canvas as a peerDependency. And wherever I put the ref
to, the same error happens