Skip to main content

Posts

Showing posts with the label React Component

How to detect page scroll to bottom of a React component

Depending on your UI framework, some of them don't really support scroll aware components. If you had to work on one of them, then this will be great for you. I had to work with one of the old UI frameworks with ReactJs. It didn't support any scroll event awareness by default. So, I had to write some custom logic to do that. Following is a sample component with scroll event awareness to detect the bottom. class MyComponent extends React.Component { constructor(props) { super (props); //atBottom state is kept to smooth things out, // to avoid again and again detecting the bottom event if we are at the bottom this .state = {atBottom : false }; // This binding is necessary to make `this` work in the callback this .handleScroll = this .handleScroll.bind( this ); } handleScroll(event) { console.log( "scrolled" ); const element = document .getElementById( 'mylist' ); if ( ! this .st...