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

Documentation for custom parent element

Open CoinCoderBuffalo opened this issue 6 years ago • 5 comments

It would be really nice to see an example of how to implement this custom parent feature. The documentation just shows a class override. Can anyone share a working example? Thanks

CoinCoderBuffalo avatar Oct 09 '18 13:10 CoinCoderBuffalo

In version 1.2.2 that's just been released, we've replaced the need to use a class override.

Instead you can pass a getScrollParent prop that returns the element that you need to use as the scroll parent.

https://github.com/CassetteRocks/react-infinite-scroller#custom-parent-element

<div style="height:700px;overflow:auto;" ref={(ref) => this.scrollParentRef = ref}>
    <div>
        <InfiniteScroll
            pageStart={0}
            loadMore={loadFunc}
            hasMore={true || false}
            loader={<div className="loader" key={0}>Loading ...</div>}
            useWindow={false}
            getScrollParent={() => this.scrollParentRef}
        >
            {items}
        </InfiniteScroll>
    </div>
</div>

I'm working on demos of more scenarios:

  • The exsting window example
  • Div element as scroller
  • Custom parent scroller

Going to tag this issue as v2 so that I can close it when there is a proper demo of custom scroll parent avaialable.

danbovey avatar Oct 10 '18 09:10 danbovey

Awesome. Thank you.

CoinCoderBuffalo avatar Oct 11 '18 20:10 CoinCoderBuffalo

In relation to custom parent element when passing getScrollParent prop react complains:

Warning: React does not recognize the getScrollParent prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase getscrollparent instead. If you accidentally passed it from a parent component, remove it from the DOM element

Never Mind Fixed 👍 all i had to do is pull the latest update :)

WalidKurchied avatar Nov 08 '18 09:11 WalidKurchied

The documentation says it requires a ref, but it only works when I pass a ReactElement. Has this changed and did the documentation not change with it?

wanjakrah avatar Jul 27 '20 13:07 wanjakrah

Awesome. Thank you.

Alireza17224 avatar Sep 27 '22 16:09 Alireza17224