How can I use orginal javascript Web APIs inside react

I quickly create a react app by create-react-app,

When I call new ImageCapture inside componentDidMount()

componentDidMount() {
    imageCapture = new ImageCapture(track);

It shows

ReferenceError: imageCapture is not defined

Don't know is it eslint block my call or something else

I've test this function in plain JS and it's work. Thanks all.

1 answer

  • answered 2017-10-20 11:26 Craig Ayre

    You need to declare imageCapture using const/let/var.

    Without using a declaration you are defining the variable to be global which will throw a ReferenceError in strict mode.


    const imageCapture = new ImageCapture(track)