vre2h/use-react-screenshot

Screenshot doesn't work, takeScreenshot returns null

Closed this issue · 1 comments

Hello,

I'm trying to use the lib, but it doesn't return any data on screenshot. This is how I implemented the feature :

`import { useScreenshot } from 'use-react-screenshot'

const ExportButton = ({ chartRef }) => {

const { context, setContext } = useContext(Context)
const [exporting, setExporting] = useState(false)
const [image, takeScreenshot] = useScreenshot()

const doExportPDF = () => {
console.log('Exporting PDF...')
setExporting(true)
takeScreenshot(chartRef.current).then((imageData) => {

  console.log(imageData, image)
  
  axios.post('/export/' + context.userKey,
    { imageData: JSON.stringify(imageData) },
    {
      responseType: 'blob',
      headers: {
        'Authorization': 'Bearer ' + Cookies.get('fileToken'),
        'Content-Type': 'application/json'
      }
    }
  ).then(
    (response) => {
      console.log('Exported PDF')
      FileDownload(response.data, 'Export.pdf')
      setExporting(false)
    },
    (error) => {
      throwErrorNotification('Error when exporting the PDF' + error)
      setExporting(false)
    }
  )
})

}`

Basically imageData and image variables are empty.
Any ideas ?

Fyi I have the version 4.0.0 of the use-react-screenshot library.
and version 1.4.1 of html2canvas.

Resolved, I had to use the ref on a real html tag, doesn't work on custom react tags.