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

127
Views
useState does not re-render
const [searchText, setSearchText] = useState('')

  const searchHandler = async (searchTextInput) => {
    console.log('search is:::', searchTextInput)
    setSearchText(() => searchTextInput)
  }

  const searchOnSubmitHandler = async () => {
    await loadShopsCount()
    await loadShops()
  }

  const searchClearHandler = async () => {
    setSearchText(() => "")
    console.log('onClear-----------search is:::', searchText)
    await loadShopsCount()
  }

On calling searchClearHandler after searching for something, searchText returns the previous state value instead of empty string. Hence, my component is not able to re-render.

How can I set searchText to empty string and re-render the component on calling searchClearHandler?

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

0

Use useEffect.

useEffect(() => {
    Here your function which you want to call.
  }, [searchText]);
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!