npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-typewriter-animation

v3.5.2

Published

A modern, performant React hook for creating typewriter animation effects with full TypeScript support and SSR compatibility.

Downloads

1

Readme

use-typewriter-animation

A modern, performant React hook for creating typewriter animation effects with full TypeScript support, accessibility features, and React 19 compatibility.

npm version License: MIT Downloads Bundle Size TypeScript React GitHub Stars

✨ Features

  • 🎯 Modern React: Built for React 16.8+ with full React 19 support
  • 🔧 TypeScript First: Complete type safety and IntelliSense
  • Accessibility: WCAG 2.1 AA compliant with screen reader support
  • 🚀 Performance: Optimized with virtualization for large text (~15KB bundle)
  • 🎨 Flexible: Rich styling and animation control
  • 📱 Responsive: Mobile-friendly with touch support
  • 🔄 Server-Side: SSR and RSC compatible
  • 🎮 Interactive: Keyboard controls and event handling
  • 🌐 Universal: Works in all modern browsers

📦 Installation

# bun (recommended)
bun add use-typewriter-animation

# npm
npm install use-typewriter-animation

# yarn
yarn add use-typewriter-animation

# pnpm
pnpm add use-typewriter-animation

🚀 Quick Start

import { useEffect } from 'react';
import { useTypewriter } from 'use-typewriter-animation';

function App() {
  const { typewriter, elements, cursor, keyframes } = useTypewriter();

  useEffect(() => {
    typewriter.type('Hello, World!').pauseFor(1000).deleteLetters(6).type('React!').start();
  }, []);

  return (
    <>
      <style>{keyframes}</style>
      <div>
        {elements}
        {cursor}
      </div>
    </>
  );
}

🎯 Key Examples

Basic Animation

const { typewriter, elements, cursor, keyframes } = useTypewriter({
  typeSpeed: 50,
  cursorStyle: 'bar',
});

useEffect(() => {
  typewriter
    .type('Welcome to React!')
    .pauseFor(2000)
    .deleteAll()
    .type('Built with TypeScript!')
    .start();
}, []);

Colorful Text

useEffect(() => {
  typewriter
    .type('This is ')
    .colorize('#3b82f6')
    .type('blue text')
    .colorize('#ef4444')
    .type(' and red text')
    .start();
}, []);

Accessibility First

const { typewriter, elements, cursor, keyframes, accessibilityProps, screenReaderAnnouncement } =
  useTypewriter({
    respectReducedMotion: true,
    ariaLabel: 'Welcome message',
    announceCompletion: true,
  });

return (
  <>
    <style>{keyframes}</style>
    <div {...accessibilityProps}>
      {elements}
      {cursor}
      {screenReaderAnnouncement}
    </div>
  </>
);

📚 Documentation

🚀 Getting Started

🔧 API Reference

🎯 Feature Guides

📚 Examples

⚡ Performance

Optimized for production use:

  • Bundle Size: 5.3KB gzipped (ESM) / 5.6KB gzipped (CJS)
  • Memory Efficient: Virtualization for large text
  • Smooth Animations: GPU-accelerated CSS
  • Zero Dependencies: No external runtime dependencies

Bundle Analysis

  • ESM Bundle: 15KB raw → 5.3KB gzipped
  • CJS Bundle: 16KB raw → 5.6KB gzipped

Measurements taken with our actual build output. Run bun run analyze to verify these numbers yourself.

♿ Accessibility

Built with accessibility as a first-class citizen:

  • ✅ WCAG 2.1 AA compliant
  • ✅ Screen reader support with ARIA live regions
  • ✅ Reduced motion support respects user preferences
  • ✅ Keyboard navigation with customizable shortcuts
  • ✅ Focus management for interactive elements
  • ✅ Semantic HTML with proper ARIA attributes

🌐 Browser Support

  • Modern Browsers: Chrome 88+ | Firefox 85+ | Safari 14+ | Edge 88+
  • Mobile: iOS Safari 14+ | Android Chrome 88+
  • React: 16.8+ | 17+ | 18+ | 19+ (full compatibility)

🔧 Essential Configuration

const { typewriter } = useTypewriter({
  // Visual Settings
  typeSpeed: 50, // Typing speed (ms per character)
  deleteSpeed: 30, // Delete speed (ms per character)
  cursorStyle: 'bar', // 'bar' | 'block' | 'underline'
  cursorColor: '#000', // CSS color value

  // Accessibility
  respectReducedMotion: true, // Honor user preferences
  ariaLabel: 'Typewriter', // ARIA label
  announceCompletion: true, // Screen reader announcements

  // Performance
  enableVirtualization: true, // For large text
  maxVisibleSegments: 100, // Virtualization limit

  // Interaction
  enableKeyboardControls: true, // Keyboard shortcuts
  loop: false, // Continuous loop
});

🎮 Control Methods

typewriter
  .type('Hello, World!') // Type text
  .pauseFor(1000) // Pause for duration
  .deleteLetters(5) // Delete characters
  .deleteWords(2) // Delete words
  .deleteAll() // Clear all text
  .colorize('#ff0000') // Change color
  .newLine() // Line break
  .on('end', callback) // Event listener
  .start(); // Start animation

🧪 Testing

// Mock for tests
Object.defineProperty(window, 'matchMedia', {
  value: jest.fn(() => ({ matches: false })),
});

test('typewriter animation', async () => {
  render(<TypewriterComponent />);
  await waitFor(() => {
    expect(screen.getByText('Hello, World!')).toBeInTheDocument();
  });
});

🚨 Common Issues

Animation Not Working?

// ❌ Missing keyframes
return (
  <div>
    {elements}
    {cursor}
  </div>
);

// ✅ Include keyframes
return (
  <>
    <style>{keyframes}</style>
    <div>
      {elements}
      {cursor}
    </div>
  </>
);

Performance Issues?

// ✅ Enable virtualization for large text
const { typewriter } = useTypewriter({
  enableVirtualization: true,
  maxVisibleSegments: 100,
});

See full troubleshooting guide →

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

MIT © Dogu Yilmaz

🔗 Links


Made with ❤️ for the React community