Skip to content

Commit 91e7f18

Browse files
authored
Merge pull request #11 from Intentface/fix-update-calling
Fix erroneus onUpdate and onError calls
2 parents 10f3aca + df4b3a1 commit 91e7f18

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/great-rules-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@intentface/react-speech-recognition": patch
3+
---
4+
5+
Fix situation where we call onUpdate and onError even when there is no support for speech recognition

index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ export function useSpeechRecognition({
110110
}, [SpeechRecognition, continuous, lang, timeout]);
111111

112112
useEffect(() => {
113+
if (!SpeechRecognition) return;
113114
if (onUpdate) onUpdate({ transcript, interimTranscript, isFinal });
114-
}, [onUpdate, transcript, interimTranscript, isFinal]);
115+
}, [onUpdate, transcript, interimTranscript, isFinal, SpeechRecognition]);
115116

116117
useEffect(() => {
118+
if (!SpeechRecognition) return;
117119
if (onError) onError({ error });
118-
}, [onError, error]);
120+
}, [onError, error, SpeechRecognition]);
119121

120122
const start = useCallback(() => {
121123
if (!recognitionRef.current) return;

0 commit comments

Comments
 (0)