Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
Is there a way to use Reacts useLocation to restart Gsaps animation timeline?

I have three links which I am currently animating to slide down when the user clicks the toggle menu button. It works fine when the user clicks the toggle again.

The problem: when the user clicks on a route and navigates away THEN comes back to select another route, the animation doesn't restart again. The animation should restart to initial position even if the user navigates to another route.

Here is what I currently have:

let linkOne = useRef(null);
let linkTwo = useRef(null);
let linkThree = useRef(null);

const [dropped, setDropped] = useState()

const tl = useRef()
useEffect(() => {
    // tl.current = gsap.timeline({paused: true})
    tl.current = new gsap.timeline()
        .to([linkOne, linkTwo, linkThree], { y: 30, stagger: { amount: .3 } });
    return tl.current.kill()
}, [])

useEffect(() => {
    dropped ? tl.current.play() : tl.current.reverse();
}, [dropped])

HTML:

<Navbar.Toggle onClick={() => setDropped(!dropped)} aria-controls="responsive-navbar-nav" />

<Nav.Link ref={el => linkOne = el} as={Link} to="/About" href="#About">About</Nav.Link>
<Nav.Link ref={el => linkTwo = el} as={Link} to="/TestPage" href="#TestPage">Test Page</Nav.Link>
<Nav.Link ref={el => linkThree = el} as={Link} to="/GsapImageReveal" href="#GsapImageReveal">GsapImageReveal</Nav.Link>

I have tried using useLocation:

let location = useLocation()
useEffect(() => {
    dropped ? tl.current.play() : tl.current.reverse();
    console.log(location)
}, [dropped, location])

This doesn't work. But i think useLocation is on the right track because it gives me a route change.

Can anyone suggest a work around or a better way to approach this?

Using react-router v6.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda