0

I'm trying to close the reader with reset() function but it's giving an error.

Here is my component:

import { BrowserMultiFormatReader } from "@zxing/browser"

const videoRef = useRef<HTMLVideoElement>(null)
const reader = useRef(new BrowserMultiFormatReader())

reader.current.decodeOnceFromConstraints(
        {
          audio: false,
          video: {
            facingMode: "environment",
          }
        },
        videoRef.current
      )
      .then((result) => {
        if (result) {
          console.log(result.getText())
        }
      })
      .catch((err) => {
        if (err) console.log(err)
      })

const handleStop = () => {
  reader.current.reset()
}

return(

  <Grid>
      <video ref={videoRef} width="400px" height="400px" />
      <Button variant="contained" onClick={handleStop}>Stop</Button>
  </Grid>
)

Here is the error. Any idea why is this happening?

Property 'reset' does not exist on type 'BrowserMultiFormatReader'.

tsm009
  • 39
  • 1
  • 9
  • I would report this on GitHub, the `reset()` method is on the `BrowserCodeReader` and all readers extends that base class. I don't see how this gives TS error when the project is written in TS. – jcubic Aug 11 '23 at 08:53
  • One thing I figure out is that `reset()` function is available with import from `@zxing/library` but not with `@zxing/browser`. And thanks @jcubic – tsm009 Aug 11 '23 at 09:20

0 Answers0