mirror of
https://github.com/dergigi/boris.git
synced 2026-02-08 00:24:46 +01:00
fix(lint): wrap createUtterance in useCallback and correct deps for hooks
This commit is contained in:
@@ -79,7 +79,7 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
||||
}
|
||||
}, [supported, defaultLang, voice, synth])
|
||||
|
||||
const createUtterance = (text: string): SpeechSynthesisUtterance => {
|
||||
const createUtterance = useCallback((text: string): SpeechSynthesisUtterance => {
|
||||
const SpeechSynthesisUtteranceConstructor = (window as Window & typeof globalThis).SpeechSynthesisUtterance
|
||||
const u = new SpeechSynthesisUtteranceConstructor(text) as SpeechSynthesisUtterance
|
||||
u.lang = voice?.lang || defaultLang
|
||||
@@ -131,7 +131,7 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
}, [voice, defaultLang, rate, pitch, volume])
|
||||
|
||||
const stop = useCallback(() => {
|
||||
if (!supported) return
|
||||
@@ -156,7 +156,7 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
||||
|
||||
utteranceRef.current = u
|
||||
synth!.speak(u)
|
||||
}, [supported, synth, voice, rate, pitch, volume, defaultLang])
|
||||
}, [supported, synth, createUtterance, rate])
|
||||
|
||||
const pause = useCallback(() => {
|
||||
if (!supported) return
|
||||
@@ -199,7 +199,7 @@ export function useTextToSpeech(options: UseTTSOptions = {}): UseTTS {
|
||||
if (utteranceRef.current) {
|
||||
utteranceRef.current.rate = rate
|
||||
}
|
||||
}, [rate, supported, synth])
|
||||
}, [rate, supported, synth, createUtterance])
|
||||
|
||||
const updateRate = useCallback((newRate: number) => {
|
||||
setRate(newRate)
|
||||
|
||||
Reference in New Issue
Block a user