I created a search field, and I want this input to search as the user types word. But I don't want it to search letter by letter (that would be too expensive, and stupid). How can I create a funcion that reads the changes from my state, but wait for like 500ms and then finally search it. My code is like this right now:
const [searchField, setSearchField] = React.useState("");
cosnst [images, setImages] = React.useState([]);
React.useEffect(() => {
getAllImages()
}
, [searchField])
const getAllImages = async () => {
const imagesQuery = await axios.get("my-api-url");
setImages(imagesQuery.data)
}
I tried using a setTimeOut... But the useEffect keeps acumulating re-renders...