Using debounce for search input - first run #174
Answered
by
outbackStack
outbackStack
asked this question in
Q&A
-
Is it possible to get debounce to run the first time without the timer? Then second time it can use the timer. import { debounce } from "@solid-primitives/scheduled";
const [value, setValue] = createSignal(");
const handleSubmit = () => {
console.log("submitting...");
};
createEffect(
on(value, () => {
const trigger = debounce(() => handleSubmit(), 500);
trigger();
return () => trigger.clear();
})
); |
Beta Was this translation helpful? Give feedback.
Answered by
outbackStack
Aug 11, 2022
Replies: 1 comment 2 replies
-
I've added in a signal to track the first run and it works with this code. const [isFirstRun, setIsFirstRun] = createSignal(true);
createEffect(
on(value, () => {
let trigger;
if (isFirstRun()) {
console.log("run for the first time...");
handleSubmit();
setIsFirstRun(false);
}
if (!isFirstRun()) {
console.log("run for the second time...");
trigger = debounce(() => handleSubmit(), 500);
trigger();
}
return () => trigger.clear();
})
); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
outbackStack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've added in a signal to track the first run and it works with this code.
Thank you for making this debounce package. It's awesome :-)