Debouncing #373
-
First of all, thank you for creating this great library!💎 I want to use debouncing: import { useQueryState } from 'next-usequerystate';
import { useDebouncedCallback } from 'use-debounce';
export default function Component() {
const [searchQuery, setSearchQuery] = useQueryState('searchQuery', {
history: 'replace',
});
const handleSearch = useDebouncedCallback((val) => {
setSearchQuery(val, {
shallow: false,
});
}, 1000);
return (
<input
// value={searchQuery}
onChange={(e) => handleSearch(e.target.value)}
/>
)
} This works as expected, but using (I read here #351 that there's an internal 50ms debounce, but I want to use a bigger number) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Well, seems like using |
Beta Was this translation helpful? Give feedback.
-
You need to keep in mind that, because of the internal throttling, there are two update events.
So it depends what you want to throttle. Since you're binding the state to a text input, I'd wager you want to keep the UI responsive and only throttle URL updates and requests sent to the server. Throttling the Ideally, the throttling value should be configurable instead of being hard-coded to 50ms. Though I'm not sure how this could be done with multiple queries with different throttle configurations, since there is only one timer in charge of flushing the update queue to the URL. If you have any ideas on that, I'm all ears. |
Beta Was this translation helpful? Give feedback.
-
Configurable throttling was introduced in version useQueryState('query', { throttleMs: 500 }) |
Beta Was this translation helpful? Give feedback.
Configurable throttling was introduced in version
1.10.0
: