Skip to content

Commit

Permalink
Fix erroneus onUpdate and onError calls
Browse files Browse the repository at this point in the history
  • Loading branch information
latenssi committed Sep 6, 2024
1 parent 10f3aca commit df4b3a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-rules-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intentface/react-speech-recognition": patch
---

Fix situation where we call onUpdate and onError even when there is no support for speech recognition
6 changes: 4 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ export function useSpeechRecognition({
}, [SpeechRecognition, continuous, lang, timeout]);

useEffect(() => {
if (!SpeechRecognition) return;
if (onUpdate) onUpdate({ transcript, interimTranscript, isFinal });
}, [onUpdate, transcript, interimTranscript, isFinal]);
}, [onUpdate, transcript, interimTranscript, isFinal, SpeechRecognition]);

useEffect(() => {
if (!SpeechRecognition) return;
if (onError) onError({ error });
}, [onError, error]);
}, [onError, error, SpeechRecognition]);

const start = useCallback(() => {
if (!recognitionRef.current) return;
Expand Down

0 comments on commit df4b3a1

Please sign in to comment.