Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
How to debounce a function?

I am trying to set a timer for onChange but I don't understand why it doesn't work. I tried several methods, but none of them worked. What can I change to make it work?

import React, {useState} from 'react'
import { debounce } from "lodash";
const Search = ({getQuery}) => {
const [text, setText] = useState('')

 const onChange = (q) => {
    setText(q)
    getQuery(q)
}

const handleDebounce = () => {
    debounce(onChange, 3000);
};

return (
    <section className='search'>
        <form>
            <input 
            type='text'
            className='form-control'
            placeholder='Search characters'
            value={text}
            onChange={(e) => handleDebounce( onChange(e.target.value), 3000)}
            autoFocus
            />
        </form>
    </section>
)}

export default Search
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

removce handleDebounce completely and call your own onChange at the input onChange

onChange={onChange}

then adjust your onChange implementation as:

const onChange = (e) => {
  const query = e.target.value;
  setText(query);
  debounce(() => getQuery(query), 3000);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!