1.0.0 • Published 2 years ago

react-use-typewriter v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

React Typewriter effect hook

Getting Started

npm install --save react-use-typewriter

Or

yarn add react-use-typewriter

Usage Example

import useTypewriter from "react-use-typewriter";

const Example = () => {
  const words = ["react", "typescript", "nodejs"];
  const currentWord = useTypewriter({words});

  return (
    <div>
      {currentWord}
      <span className="cursor">|</span>
    </div>
  );
}

Options

NameTypeDefault valueDescription
wordsArraynullRequired, words for typing
typeSpeednumber100Speed in ms for each letter to type
afterTypingDelaynumber1000Delay in ms after typing has finished
eraseWordsbooleantrueWhether or not to erase after typing
eraseSpeednumber50Speed in ms for each letter to erase
afterErasingDelaynumber1000Delay in ms after erasing has finished

CSS for blinking cursor

Blinking cursor is not included but can be implemented easily with CSS:

@keyframes blink {
  from, to {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.cursor {
  animation: blink 1s linear infinite forwards;
}