ankeetmaini / react-infinite-scroll-component

An awesome Infinite Scroll component in react.
https://react-infinite-scroll-component.netlify.com/
MIT License
2.88k stars 323 forks source link

How can I change the scrollY when the InfiniteScroll has rendered #401

Open 17dun opened 5 months ago

17dun commented 5 months ago

in my project I want change the scrollY when user click some button,I tryed change initialScrollY use the useState hooks,but it does not work :(

17dun commented 5 months ago

`const [initialScrollY, setInitialScrollY] = useState(0); useEffect(() => { if (searchParams?.get('filter')) { setInitialScrollY(300); } else { setInitialScrollY(0); } }, [searchParams]); <InfiniteScroll initialScrollY={initialScrollY} dataLength={searchList.length} next={getSearchListMore} hasMore={hasMore} loader={} hasChildren scrollableTarget="scrollableDiv" className="flex-1 flex-grow overflow-y-scroll no-scrollbar" height="calc(100vh - 96px)"

....`

my code like this

sapiens-shahbaz-khan commented 4 months ago

I haven't tried this prop, but we can use ref on the container and do something like ref.current.scrollTop = 0