Skip to content
RED SAGSkills
medium10 pts · first answer countsreactrace-conditionsdata-fetching

Search shows results for old input

Typing "react" quickly sometimes shows results for "re", because that slower response arrives last. What is the best fix in this effect?

useEffect(() => {
  fetch('/api/search?q=' + encodeURIComponent(query))
    .then((r) => r.json())
    .then(setResults)
}, [query])
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions