← Components/AI-Specific

StreamingText

real-timestreamingtextrevealeffecttokenTypeScript
streaming-text-v1.tsx
import React, { useState, useEffect } from 'react';

interface Props {
  text: string;
  speed: number;
}

const StreamingText: React.FC<Props> = ({ text, speed }) => {
  const [displayedText, setDisplayedText] = useState('');
  const [tokens, setTokens] = useState(text.split(''));
  const [index, setIndex] = useState(0);

  useEffect(() => {
    const intervalId = setInterval(() => {
      if (index < tokens.length) {
        setDisplayedText(displayedText + tokens[index]);
        setIndex(index + 1);
      } else {
        clearInterval(intervalId);
      }
    }, speed);
    return () => clearInterval(intervalId);
  }, [index, tokens, displayedText, speed]);

  return (
    <div style={{ backgroundColor: '#0A0A0A', color: '#F5F5F0', padding: '20px' }}>
      {displayedText}
    </div>
  );
};

export default StreamingText;

Component info

CategoryAI-Specific
Frameworkreact
TierPREMIUM
Views6
Copies0

Dependencies

npm install reactnpm install react-dom

About

StreamingText is a React component designed to display real-time streaming text with a token by token reveal effect. It is built with TypeScript and features a dark background. The component is customizable, allowing you to change the speed of the reveal effect and the text to be displayed. It is perfect for creating engaging and interactive user interfaces, such as live updates, news feeds, or chat applications. With its sleek and modern design, StreamingText is sure to enhance the user experience of your application. The component is also optimized for performance, ensuring that it runs smoothly even with large amounts of text. Whether you're building a real-time analytics dashboard or a live blogging platform, StreamingText is the perfect choice for displaying dynamic text content.

Pro component
Unlock this component and 17,500+ more with Empire UI Pro.
Get Pro →