I am going to update state when I scrolled bottom of a div. I have succeeded to detect user scrolled bottom of div but updating the state always logs initial value. Here is my code.
const ExampleApp = () => {
const [value, setValue] = useState(0);
useEffect(() => {
document.addEventListener('scroll', trackScrolling);
return () => {
document.removeEventListener('scroll', trackScrolling);
}
}, []);
const trackScrolling = () => {
const wrappedElement = document.getElementById('vContainer');
if (isBottom(wrappedElement)) {
// Here user scrolled to bottom of a div
console.log('Log Value: ', value); // I want to see the increased value, but always logs 0 every time I scrolled bottom.
setValue(value + 1);
}
}
}
I am curious why the value NOT increased every time I detect bottom of a view. And what is the solution to increase the state value when I detect bottom. Thanks in advance.