I'm trying to make new requests whenever user reach the bottom with the following; useEffect(() => { const scrolling_function = () => { if((window.innerHeight + window.scrollY) >= document.body.offsetHeight-10){ window.removeEventListener('scroll',scrolling_function) getMoviesFromApi() } } window.addEventListener('scroll', scrolling_function); }, []) But the state objects that I defined, such as: const[selectedGenres, setSelectedGenres] = useState(new Set()) All becomes undefined in the inside of my useEffect hook, and thus my getMoviesFromApi() method does not work properly. My question is, is that expected behavior? If so, how could I overcome it? The getmoviesfromapi method: const getMoviesFromApi = async () => { setLoading(true) let init, end; if(initialYear>endYear) { init = endYear end = initialYear } else { init = initialYear end = endYear } let res =...
A site where you can share knowledge