maxeth / react-type-animation

A React typewriter animation based on typical with extended functionality and customization.
https://react-type-animation.netlify.app/
MIT License
427 stars 24 forks source link

Have initial text ready #20

Closed kevinlu1248 closed 1 year ago

kevinlu1248 commented 1 year ago

Hello,

Awesome package btw. I was wondering if there's a way of having initial text there, instead of initially having nothing and typing it out the first time.

maxeth commented 1 year ago

Hi, since the default wrapper for the animation is a <span>, you could just do something like this:

<span style={{ fontSize: '2em' }}>
      <span>We produce food for</span>{' '} // <--- will be pre-typed
      <TypeAnimation
        sequence={[
          'Mice',
          1000,
          'Hamsters',
          1000,
          'Guinea Pigs',
          1000,
          'Chinchillas',
          1000,
        ]}
        repeat={Infinity}
      />
</span>

But in that case, you couldn't animate that pre-typed string later in the animation sequence.

kevinlu1248 commented 1 year ago

Oh I meant like it is "We produce food for Mice" initially and "Mice" gets replaced by "Hamsters", etc.

maxeth commented 1 year ago

I see, so something like

    <TypeAnimation
       preRenderFirstString={true}
        sequence={[
          'A'
          1000,
          'B',
          1000,
          'C',
          1000
        ]}
        repeat={Infinity}
      />

Results in: 'A' (pre-rendered), 1s delay, 'B', 1s delay, 'C', 1s delay, 'A', ...

Sounds like a good feature, especially for SEO if you use server-side rendering. It's not possible yet but I'll add it in the following days.

asp3 commented 1 year ago

hey! checking in on the preRenderedFirstString prop @maxeth

maxeth commented 1 year ago

hey! checking in on the preRenderedFirstString prop @maxeth

Added in version 3.1.0 https://react-type-animation.netlify.app/examples#initially-pre-rendered