Skip to content

Debounce Input for performing a query in urql #1547

Answered by JoviDeCroock
deadcoder0904 asked this question in Q&A
Discussion options

You must be logged in to vote

There are a few options here, you can set the value synchronouosly so the UI doesn't get delayed and queue up a debounce(setState) for the thing you are passing down:

const Home = () => {
  const timeout = React.useRef(null);
  const [acquisitionPriceRange, setAcquisitionPriceRange] = React.useState([0, 1000000000])
  const [price, setPrice] = React.useState([0, 1000000000])
  
  React.useEffect(() => {
    timeout.current = setTimeout(() => {
      setAcquisitionPriceRange(price)
      timeout.current = null;
    }, 2000)
    return () => {
      if (timeout.current) clearTimeout(timeout.current)
    }
  }, [price])

now we use setPrice in the slider and have <AcquisitionList minPrice={a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@deadcoder0904
Comment options

Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants