diff --git a/.changeset/great-rules-sleep.md b/.changeset/great-rules-sleep.md new file mode 100644 index 0000000..eede36e --- /dev/null +++ b/.changeset/great-rules-sleep.md @@ -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 diff --git a/index.ts b/index.ts index e24ce6e..b998c8e 100644 --- a/index.ts +++ b/index.ts @@ -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;