Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
Delaying router pathName until after next-page-transitions is done

I have two separate things going on in a simple setup. I am using the following code:

className={router.pathname.startsWith("/pagename") ? "menu-active" : ""}

to assign the menu-active class to the pagename nav link when we're on the pagename page.

And I am using

        <PageTransition timeout={450} classNames="page-transition">
      <Component {...pageProps} key={router.route} />
        </PageTransition>
        <style jsx global>{`
          .page-transition-enter {
            opacity: 0;
          }
          .page-transition-enter-active {
            opacity: 1;
            transition: opacity 450ms;
          }
          .page-transition-exit {
            opacity: 1;
          }
          .page-transition-exit-active {
            opacity: 0;
            transition: opacity 450ms;
          }
        `}</style>

pretty much verbatim from the next-page-transitions docs page, to have a 450ms fade to white between pages.

Here's the problem. I use menu-active to change the font-style of the active page link to italics, and to change its color to orange. But when you change pages, it seems that the class is applied before the transition happens. In other words, you can see the menu change before the fade out to white even occurs.

I figured I could delay the transition by 450ms and then the change would happen right as the fade was finishing, and that works fine for the color change; but not for the font style. Since font style doesn't work with transition-delay, I am trying to figure out some other way to delay the application of this class/style.

Perhaps I'm going about this all wrong though. Any recommendations?

EDIT: to be clear, I'm in no way married to using next-page-transitions, so feel free to recommend something else for doing what I want to do.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can try creating two different components, they will be the same but with different font family. by that, you will be able to setTimeout of 450ms for the components to change between them, and this will give you the desired solution.

This is a bit dirty, but atm thats what I managed to think about as adding transition to fonts is problematic.

Will update if any new ideas come to mind

Edit:

I made a small code example for you. i used styled-components, its just like regular css just has different code style, its very easy to convert it to regular css. And i used react-hooks, for the useState and useEffect. please read about it if you dont understand, its important to know this in order to code in react.

const FontX = styled.p`
  font-family: 'Andale Mono';
`;

const FontY = styled.p`
  font-family: Arial;
`;

const Container = () => {
  const [Component, setComponent] = useState(FontX);

  useEffect(() => {
    setTimeout(() => {
      setComponent(FontY);
    }, 450);
  }, []);

  return <Component>Look here! Font will change after 450ms</Component>;
};

here sandbox:

https://codesandbox.io/s/strange-yonath-dp4w5?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda