Search code examples
next.jsreact-transition-group

Nextjs + react-transition-group don't animate


I'am in trouble with nextjs + react-animation-group, I'have follow the docs to implement but doesn't work, i need to animate a component from opacity 0 to 1 in 2.5 sec. here my test:

https://codesandbox.io/s/transition-group-u5htd

you can see that "Animation div" appear instantly instead with opacity transition, any ideas how to solve?

Thx all


Solution

  • Try This :-

    pages/_app.js

    export default function MyApp({ Component, pageProps, router }) {
      return (
        <SwitchTransition mode='out-in'>
          <CSSTransition key={router.pathname} classNames='page' timeout={300}>
            <Component {...pageProps} />
          </CSSTransition>
        </SwitchTransition>
      );
    }
    

    global.css

    .page-enter {
      opacity: 0;
      transform: scale(1.1);
    }
    .page-enter-active {
      opacity: 1;
      transform: scale(1);
      transition: opacity 300ms, transform 300ms;
    }
    .page-exit {
      opacity: 1;
      transform: scale(1);
    }
    
    .page-exit-active {
      opacity: 0;
      transform: scale(0.9);
      transition: opacity 300ms, transform 300ms;
    }```