Skip to content

sbstjn/react-capture

Repository files navigation

react-capture

Capture React component and download as PNG file using html2canvas.

react-capture

Install

yarn add react-capture

Use

import { useCapture } from 'react-capture'

export const Component = () => {
  const { snap } = useCapture()
  const element = useRef(null)

  const onClick = useCallback(() => {
    snap(element, { file: 'download.png' })
  }, [snap, element])

  return (
    <Wrapper>
      <ComponentWrapper ref={element}>
        <Component />
      </ComponentWrapper>

      <Button onClick={onClick} value="Download" />
    </Wrapper>
  )
}

About

Capture React component and download as PNG file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published