Ask questionsApollo with debounce example
Hi, thanks for an awesome library! I'm trying to figure out the correct way of throttling / debouncing the input for Apollo, would be awesome if someone could help to figure it out!
Cheers!
Answer
questions
donysukardi
@Pau1fitz, something like that. However, you might want to consider persisting the debounced callback with useRef. Otherwise, whenever your component re-renders, you'd get a new instance of the function, which could possibly cause some unwanted side effects.
const [currValue, setCurrValue] = useState('');
const debounceSetCurrValue = useRef(null);
if (!debounceSetCurrValue.current) {
debounceSetCurrValue.current = debounce(setCurrValue, 1000);
}
return (
<Downshift onInputValueChange={debounceSetCurrValue.current}>
</Downshift>
);
Related questions