From df4b3a1cdc13c613c8cb2af6fc6691c2c3d78a82 Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Fri, 6 Sep 2024 19:15:47 +0300 Subject: [PATCH] Fix erroneus onUpdate and onError calls --- .changeset/great-rules-sleep.md | 5 +++++ index.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/great-rules-sleep.md 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;