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

131
Visualizações
Render react component after typewriter-effect animation has finished

https://hannarosenfeld.com/

Hi, I would like to display my social links after the typescript sentence has finished.

I am unsure how to achieve this, since I am kind of a beginner in React.

See my code below:

`

import React, { useEffect } from 'react'
import { Link } from 'gatsby'
import Typewriter from "typewriter-effect";

import '../styles/base.css'

function TypewriterEffect() {
  return (
    <div className="typewriter">
      <Typewriter
       onInit={(typewriter)=> {
       typewriter
       .typeString("Hello World!")
       .pauseFor(1000)
       .deleteAll()
       .typeString("I am a web developer living and working in Philadelphia, PA.")
       .typeString(" Contact me through my social links below: ")
       .pauseFor(1000)
       .start()
       document.getElementsByClassName('social')[0].classList.add('visible')
       }}
       />
    </div>
  )
}
const IndexPage = () => {
    return (
        <>
            <header>
                <h1>
                    <Link className="hzr" to="/">&lt;hzr/&gt;</Link>
                </h1>
                <TypewriterEffect/>
                <p id="typewriter"></p>
                <div>
                    <Link className="social" to="https://github.com/hannarosenfeld">&gt; github</Link>
                </div>
            </header>
        </>
    )
}

export default IndexPage

`

I tried attaching a css attribute in the onInit={(typewriter)=\> {..})} function, sadly that did not work.

Code I used:

document.getElementsByClassName('social')[0].classList.add('visible')

  • sadly this doesn't seem to work.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I was not able to find anything on the Typewriter API that lets you know when it ended. However there is a simple way to achieve this, that is just calculating how long it takes to type everything out, and write a setTimeout for that time that changes a property that will show your links. Something like this

import React, { useEffect, useState } from 'react';

import Typewriter from 'typewriter-effect';

const TypeWritter = () => {
  const [showLinks, setShowLinks] = useState(false);

  useEffect(() => {
    setTimeout(() => {
      setShowLinks(true);
    }, 20400);
  }, []);

  return (
    <div className="typewriter">
      <Typewriter
        onInit={(typewriter) => {
          typewriter
            .typeString('Hello World!')
            .pauseFor(1000)
            .deleteAll()
            .typeString(
              'I am a web developer living and working in Philadelphia, PA.'
            )
            .typeString(' Contact me through my social links below: ')
            .pauseFor(1000)
            .start();
        }}
      />
      {showLinks && <div>your links</div>}
    </div>
  );
};

export default TypeWritter;

Example of the code running: https://stackblitz.com/edit/react-mui-krpgmy?file=TypeWritter.jsx

about 4 years ago · Juan Pablo Isaza Relatório
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