jscottsmith / react-scroll-parallax

🔮 React hooks and components to create parallax scroll effects for banners, images or any other DOM elements.

Home Page:https://react-scroll-parallax.damnthat.tv/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't disable effect after initialization

mattoni opened this issue · comments

Hi there!

I'm unable to disable the effect after it's been initialized. The use case is that I am using SSR, but need to disable the effect on mobile due to performance. If I try to change the disabled property on the effect after the client is rehydrated, nothing happens and the effect still occurs. My expectation would be that it would be switched off. If this is not the proper way to do that, how would I go about properly disabling the effect?

Thanks!

Ya sounds like a bug but I'll need an example to know for sure.

Some questions to help me reproduce this:

Are you using the useParallax hook? Or are we talking about the ParallaxBanner component? Can you share the relevant code blocks please?

Are you using Next JS/Gatsby SSR?

It fails with both the <Parallax /> component and the useParallax hook. Basically, I'm doing this:

    const px = useParallax<HTMLDivElement>({
        speed: 50,
        disabled: scrollDisabled,
    });

and I set scrollDisabled to true on the client, in a useEffect, once the screen width has been determined.

I'm using Remix, but I imagine it'd be the same for NextJS/Gatsby.

Great, thanks, I'll look into it!

@mattoni please try updating to version v3.0.6 and let me know if the issue is resolved. Thanks!

Perfect, this worked. Thanks so much @jscottsmith !