Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Usage with Animate Presence #36

Open
connorhvnsen opened this issue Aug 20, 2022 · 0 comments
Open

Usage with Animate Presence #36

connorhvnsen opened this issue Aug 20, 2022 · 0 comments

Comments

@connorhvnsen
Copy link

Attempting scroll to top when the exit animation completes. Any ideas? The following throws the error:
TypeError: Cannot read properties of null (reading 'scrollTo')

import "../styles/globals.css";
import "../styles/locomotive-scroll.css";
import { useRef } from "react";
import { LocomotiveScrollProvider } from "react-locomotive-scroll";
import { useLocomotiveScroll } from "react-locomotive-scroll";
import { useRouter } from "next/router";
import { AnimatePresence } from "framer-motion";

function MyApp({ Component, pageProps }) {
  const containerRef = useRef(null);
  const { asPath } = useRouter(); // With next/router
  const { scroll } = useLocomotiveScroll();

  return (
    <>
      <div className="app dark">
        <LocomotiveScrollProvider
          options={{
            smooth: true,
            mobile: {
              smooth: false,
            },
            tablet: {
              smooth: false,
            },
            // ... all available Locomotive Scroll instance options
          }}
          location={asPath}
          containerRef={containerRef}
          // onLocationChange={(scroll) =>
          //   scroll.scrollTo(0, { duration: 0, disableLerp: true })
          // }
        >
          <main
            className="main dark:bg-black"
            data-scroll-container
            ref={containerRef}
          >
            <AnimatePresence
              exitBeforeEnter
              initial={true}
              onExitComplete={() =>
                scroll.scrollTo(0, { duration: 0, disableLerp: true })
              }
            >
              <Component {...pageProps} key={asPath} />
            </AnimatePresence>
          </main>
        </LocomotiveScrollProvider>
      </div>
    </>
  );
}

export default MyApp;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant