react-infinite-scroller icon indicating copy to clipboard operation
react-infinite-scroller copied to clipboard

useWindow={true} not working

Open Mihai-github opened this issue 3 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

Using useWindow={true} as the docs say "Add scroll listeners to the window, or else, the component's parentNode." should help me to achieve infinite scroll but it does nothing.

To Reproduce Please clone your layout and use of react-infinite-scroller by forking this Code Sandbox and linking it here. Doing so will massively expedite getting the bug fixed! 👊

export const InfiniteScrollerComponent = memo(
    ({
        meta,
        loadMore,
        children,
    }: {
        meta: IPageMeta;
        loadMore: () => void;
        children: React.ReactNode;
    }) => {
        const scrollParentRef = useRef<any>();
        return (
            // <div
            //     style={{height: '75vh', overflow: 'auto'}}
            //     ref={(ref: any) => (scrollParentRef.current = ref)}>
            <InfiniteScroll
                pageStart={meta && meta.currentPage}
                // loadMore
                loadMore={() => alert(1)}
                hasMore={meta?.currentPage < meta?.totalPages}
                loader={
                    <div
                        style={{
                            display: 'flex',
                            justifyContent: 'center',
                            width: '100%',
                            marginBottom: 25,
                        }}>
                        <Spinner size="xl" color="primary" />
                    </div>
                }
                style={{
                    width: '100%',
                    display: 'flex',
                    flexWrap: 'wrap',
                    flexDirection: 'column',
                }}
                threshold={1050}
                // element="body"
                // @ts-ignore
                // getScrollParent={() => {
                //     scrollParentRef;
                // }}
                useWindow={true}>
                {children}
            </InfiniteScroll>
            // </div>
        );
    },
);

Expected behavior A clear and concise description of what you expected to happen.

Not having the ability to use the browser scroll event for infinite scrolling. Something is weird because the component knows there is more to fetch because hasMore={true} but the loadMore function does not trigger at all...

Screenshots If applicable, add screenshots to help explain your problem.

image

Device (please complete the following information):

  • OS: [e.g. Mac]: macOs Big Sur 11.6
  • Browser [e.g. chrome, safari]: Chrome
  • Version [e.g. 22]: Chrome Version 97.0.4692.99 (Official Build) (x86_64)
  • "react-infinite-scroller": "^1.2.4",
  • "react": "17.0.2",

Mihai-github avatar Feb 03 '22 08:02 Mihai-github

Any update?

Eigilak avatar Jan 09 '23 19:01 Eigilak

I'm facing the same issue

KartikayDhingra avatar Jun 05 '23 07:06 KartikayDhingra