Last active
July 2, 2020 22:08
-
-
Save belal-mazlom/40d63c41befe76b2c4a5fb771ea1124f to your computer and use it in GitHub Desktop.
Activate "react-scrollbars-custom" with "react-window-infinite-loader" and also "react-window-infinite-loader"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useCallback, forwardRef } from 'react'; | |
import Scrollbar from 'react-scrollbars-custom'; | |
import InfiniteLoader from 'react-window-infinite-loader'; | |
import { FixedSizeList } from 'react-window'; | |
const CustomScrollbars = ({ onScroll, forwardedRef, style, children }) => { | |
const refSetter = useCallback((scrollbarsRef) => { | |
if (scrollbarsRef) { | |
forwardedRef(scrollbarsRef); | |
} else { | |
forwardedRef(null); | |
} | |
}, []); | |
return ( | |
<Scrollbar | |
ref={refSetter} | |
style={{ ...style, overflow: 'hidden' }} | |
onScroll={(e: any) => { | |
onScroll({ | |
currentTarget: { | |
clientHeight: e.clientHeight, | |
scrollHeight: e.scrollHeight, | |
scrollTop: e.scrollTop, | |
}, | |
}); | |
}} | |
> | |
{children} | |
</Scrollbar> | |
); | |
}; | |
const CustomScrollbarsVirtualList = React.forwardRef((props, ref) => ( | |
<CustomScrollbars {...props} forwardedRef={ref} /> | |
)); | |
// ... In your component or function | |
<InfiniteLoader {...rest} > | |
{({ onItemsRendered, ref }: any) => ( | |
<FixedSizeList | |
outerElementType={CustomScrollbarsVirtualList} | |
{...rest} | |
/> | |
)} | |
</InfiniteLoader> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this example I activate three elements together:
react-scrollbars-custom
react-window/FixedSizeList
react-window-infinite-loader