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])Discussion 0
Join free to post in the discussion.
Related questions
- Keys for rows loaded from an APIFull Stack Developer
- User bios rendered as HTMLFull Stack Developer
- Relative fetch on the serverFull Stack Developer
- Hydration mismatch with timeFull Stack Developer
- Why React lists need keysFrontend Developer
- Input that ignores typingFrontend Developer
- Changing a prop inside a childFrontend Developer
- Multiple setState callsFrontend Developer