Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,34 @@ blink. To include it, you must include
[`dist/Typist.css`](https://github.com/jstejada/react-typist/blob/69445a87314b52454f050045961ac32090739726/dist/Typist.css) in your build.

## Dynamic content usage
Provide a unique `key` prop to `Typist` so that it would re-render every time your dynamic content is changed like that:
```

You can use the `onTypingDone` method to loop through an array of dynamic text values.
The example below cycles through three strings with delays to create a dynamic typing effect.

```jsx
import React, { useState } from "react";
import Typist from "react-typist";

export default const DynamicTypist = () => {
const texts = ["first text", "second text", "third text"];
export default function DynamicTextExample() {
const texts = ["one", "two", "three"];
const [currentTextCounter, setCurrentTextCounter] = useState(0);

return <div onClick={() => if (currentTextCounter < texts.length - 1) { setCurrentTextCounter(currentTextCounter + 1) }}>
<Typist key={currentTextCounter}>
return (
<Typist
key={currentTextCounter}
onTypingDone={() => {
if (currentTextCounter < texts.length - 1) {
setCurrentTextCounter(currentTextCounter + 1);
} else {
setCurrentTextCounter(0);
}
}}
>
{texts[currentTextCounter]}
</Typist>
</div>
);
}
```


Otherwise your dynamic content **won't** be reflected and re-typed.

Expand Down