fisshy / react-scroll

React scroll component
https://github.com/fisshy/react-scroll/blob/master/README.md
MIT License
4.31k stars 435 forks source link

Using componentDidMount to trigger scrollTo with dynamic created content #343

Open c0d3x opened 5 years ago

c0d3x commented 5 years ago

I am using a Accordion type component that should scroll to the accordion body class minus the offset of accordion header.

Problem I have is when I trigger the accordion next click from the first accordion to the 2nd, the content is not matching the offset. It works if I set timout to 600ms instead of 300. But then you get a weird effect of content expanding and page scrolling after.

Is there a good way of fixing the expanding of content and scrolling at the same time?

    componentDidMount() {
        setTimeout(() => {
            scroller.scrollTo(this.props.scrollToId, {
                duration: 500,
                offset: -72,
                smooth: false,
                isDynamic: true // See no difference with this..
            });
        }, 300);
    }
ShiiRochi commented 4 years ago

I have the same problem. But for me even timeouts do not help sometimes.

jirsbek commented 4 years ago

I'm having the same problem with lazyload images that expand the content on scroll. isDynamic: true has no effect.