New React 18 Quagga2 example #480
oidualc
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
I had recently fixed a similar problem in my application that uses Quagga, but I haven't had a chance yet to see if the same problem affected the demo. From what you're saying, it sounds like it did. I'll definitely take a look, and see what I can learn. Thank you! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone, usage of Quagga with React 18+ is tricky because of this kind of how useEffect works: Quagga.init runs multiple times before Quagga.stop (in the effect cleanup) has time to stop the camera media tracks, failing to close the webcam and leading to resources leaks.
To show a simple use case of safe usage of React with version 18+ I created a new quagga2-react-example on my repo: https://github.com/oidualc/quagga2-react-example/. In particular I'm using a ref
isQuaggaInitializedRef
to ensure Quagga is initialized only once.Hope it helps.
Beta Was this translation helpful? Give feedback.
All reactions