-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #31: `listen` and `stop` were being regenerated on every render so if you called them from inside a closure, you could end up using a stale version that referenced old values of state and props. This led to confusing behavior when calling `listen` or `stop` from inside a closure, e.g. const { listen, stop } = useSpeechRecognition(); const handleClick = () => { setTimeout(stop, 1000); listen(); }; return <button onClick={handleClick}>Listen for 1 second</button>; Clicking the button would listen indefinitely because the version of `stop` inside the `handleClick` callback referenced the old value of `listening`, before `listen` was called. This commit makes it so `listen` and `stop` always reference the latest values of state and props so they can be safely called from within closures.
- Loading branch information
1 parent
9c09578
commit e6db84e
Showing
2 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters