typewriterjs icon indicating copy to clipboard operation
typewriterjs copied to clipboard

React 'Loop:false' Erase the content at the end:

Open tonytoms opened this issue 5 years ago • 3 comments

Hi. Thanks a lot for the awesome library. Actually, I am facing a problem with the react component. If My loop is set to false, the content will get erased at the end. <Typewriter options={{ strings: ['Hi,'], autoStart: true, }} />

Here the Hi will get eased after getting typed. I would have been Nice if the content stayed where it should be when the function ends. PS: It actually works properly when I am passing the values in onInit method to the component <Typewriter onInit={(typewriter) => { typewriter.typeString('Hi,') .start(); }} />

tonytoms avatar Sep 29 '20 11:09 tonytoms

I have the exact same issue. By looking at the code, e.g. this line it turns out that it iterates over all strings provided via options with type, pause, delete.

this.options.strings.forEach(string => {
      this.typeString(string)
        .pauseFor(this.options.pauseFor)
        .deleteAll(this.options.deleteSpeed);
    });

MartinSeeler avatar Nov 19 '21 14:11 MartinSeeler

A quick fix which worked for me is the following:

<Typewriter
    onInit={typewriter => {
      messages.slice(0, messages.length - 1).forEach(message => {
        typewriter.typeString(message).pauseFor(1000).deleteAll()
      })
      typewriter
        .typeString(messages[messages.length - 1])
        .pauseFor(1000)
        .start()
    }}
  />

MartinSeeler avatar Nov 19 '21 15:11 MartinSeeler

Having the same problem - this library always deletes the text after it renders for some reason. There doesn't seem to be an option to disable that behavior which makes it totally useless for most use cases.

bennyschmidt avatar Feb 12 '24 16:02 bennyschmidt