jscottsmith / react-scroll-parallax

🔮 React hooks and components to create parallax scroll effects for banners, images or any other DOM elements.
https://react-scroll-parallax.damnthat.tv/
MIT License
2.86k stars 158 forks source link

Could not find `react-scroll-parallax` context value. Please ensure the component is wrapped in a <ParallaxProvider> #233

Closed burasov-artyom closed 9 months ago

burasov-artyom commented 10 months ago

Good afternoon. I can't use this library after moving the project from CRA to Next.js. I get an error that the provider cannot be imported, although it is added to _app.jsx.

Has anyone encountered a similar problem?

_app.jsx

const App = ({ Component, pageProps }) => {
    return (
        <ParallaxProvider>
            <WagmiConfig config={wagmiConfig}>
                <ScrollToTop />

                <ApolloProvider client={defaultClient}>
                    <Provider store={store}>
                            <Component {...pageProps} />
                    </Provider>
                </ApolloProvider>
            </WagmiConfig>
        </ParallaxProvider>
    )
}

parallax component

import { useParallax } from "react-scroll-parallax";

const Bubble = ({ isLeft, className, children }) => {
    const { ref } = useParallax({
        rotate: isLeft ? [0, 20] : [0, -20],
        translateY: [40, -40]
    });

    return (
        <div className={className} ref={ref}>
            { children }
        </div>
    );
};

export default Bubble;

List of related npm package versions

"next": "^14.0.2",
"react-scroll-parallax": "^3.4.3",
TechSynthesis commented 10 months ago

I have the same issue. Been trying to resolve it for months

raRaRa commented 10 months ago

I have a PR that should fix these issues: https://github.com/jscottsmith/react-scroll-parallax/pull/234

jscottsmith commented 10 months ago

Please try v3.4.4 to see if this issue is resolved.

burasov-artyom commented 10 months ago

Problem resolved. Thanks a lot

burasov-artyom commented 10 months ago

After fixing the problem, the following error is spammed in the console

изображение

jscottsmith commented 10 months ago

@burasov-artyom Can you provide some steps to reproduce? Guessing this happens after making changes, but I haven't been able to verify on my end.

raRaRa commented 10 months ago

I'm having the same issue on certain pages that don't have any Parallax components. Maybe that could be related to the issue? It works if I start on a page that has Parallax components and then navigate to another one without any with client-side routing.

raRaRa commented 10 months ago

Well, maybe not the same error:

Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at ParallaxController._handleScroll (parallax-controller.esm.js:1064:1)
jscottsmith commented 10 months ago

Thanks, I was able to reproduce the error. I'll look into it.

jscottsmith commented 10 months ago

Alright, give v3.4.5 a try.

burasov-artyom commented 9 months ago

Great! Works without errors