profile
viewpoint

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!

downshift-js/downshift

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>
);
useful!

Related questions

TypeScript compiler error with ref passed from getInputProps to component using a forwardRef hot 2
Double rendering (Lifecycle hook scheduled a cascading update) after item selection hot 1
TypeScript: definitions missing `preventDownshiftDefault` hot 1
Errors "You returned a non-DOM element. You must specify a refKey in getRootProps" hot 1
Support RefObjects for sub-components hot 1
Switching between controlled and uncontrolled input hot 1
source:https://uonfu.com/
Github User Rank List