简体   繁体   中英

How to add a link to the typewriter effect in react?

I am using the typewriter effect in react, and want to add a link to the second line (where is says "learn more about me") so that when you click it it sends the user to the about me page, but I am confused as to how to do it. I tried using href or onclick but neither work. please help.

<Typewriter
  onInit={(typewriter)=> {
  typewriter
  .typeString("Hi")
  .pauseFor(1000)
  .deleteAll()
  .typeString("Learn More about me") 
  .start();
  }}
/>

Change state after .deleteAll and render component with an a wrapper.

const [isLink, setIsLink] = useState(false);
const init = (typewriter)=> {
  typewriter
  .typeString("Hi")
  .pauseFor(1000)
  .deleteAll()
  .callFunction(() => setIsLink(true))
  .typeString("Learn More about me") 
  .start();
}
return (
  isLink
  ? <a href="https://google.com">
    <Typewriter
      onInit={init}
    />
  </a>
  : <Typewriter
    onInit={init}
  />
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM