Skip to content

Commit

Permalink
Merge pull request #11 from Intentface/fix-update-calling
Browse files Browse the repository at this point in the history
Fix erroneus onUpdate and onError calls
  • Loading branch information
latenssi authored Sep 6, 2024
2 parents 10f3aca + df4b3a1 commit 91e7f18
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 91e7f18

Please sign in to comment.