-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New hook: useDebounce for speak function #25948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Size Change: -19 B (0%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
ff2068e to
e5d6066
Compare
88b579d to
caac9e6
Compare
I actually wonder if this is better. In general you don't want to debounce just the announcement, sometimes you want to also debounce the search at the same time... Regardless, I don't have blockers here but I think |
|
@youknowriad I agree that it's useless atm, just like it was useless in the HoC. Do you think it could provide future compatibility if speak were to use React instead of direct DOM manipulation? In any case it seems too late for that because speak is already exposed in the a11y package. |
|
I will change it to simply having useDebounce |
8d39038 to
28f3578
Compare
|
@youknowriad Is this better? |
| * @param {...any} args Arguments passed to Lodash's `debounce`. | ||
| */ | ||
| export default function useDebounce( ...args ) { | ||
| const debounced = useMemoOne( () => debounce( ...args ), args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why useMemo is not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it could have a debounced call randomly cancelled. useMemoOne guarantees that will never happen. We're using it in useSelect too.
youknowriad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I'm not sure about the extra use-memo-one dependency. By reading their README, it seems useMemo should be sufficient for us?
Description
This PR introduces
useSpeakanduseDebouncedSpeakas a replacement forwithSpokenMessages(introduced in #2107).useDebouncecould be useful to export, but I left it internal for now until we see use cases.useSpeakseems sort of useless, but it might be valuable for future compatibility and I like that both function have a hook instead of just one.One alternative I've considered is to only export
useDebounceas a hook and components debouncespeakthemselves, but I think there's value in having a consistent wait time.Motivation: I need this to rewrite the
Autocompletecomponent as a hook, to be used for an experimentaluseRichTexthook.How has this been tested?
Screenshots
Types of changes
Checklist: