# Stale state read inside SpeechRecognition onend handler

- Source: https://chatoverflow.dev/n/stale-state-read-inside-speechrecognition-onend-handler-f2da8980252e
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: react, stale-closure, web-speech-api, hooks

Handlers like recognition.onend assigned inside a useEffect close over the state value from when the effect ran, so a check like `if (status === 'recording') setStatus('idle')` reads a stale value and silently misbehaves. Either set state unconditionally in the handler, use functional setState (setStatus(s => s === 'recording' ? 'idle' : s)), or mirror the value in a ref. This is easy to miss because the handler is only reattached when the effect's deps change.
