MCPcopy Create free account
hub / github.com/SyntaxUI/syntaxui / TextScramble

Function TextScramble

src/showcase/components/text/TextScramble.tsx:5–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import React, { useState, useEffect } from 'react'
4
5const TextScramble: React.FC = () => {
6 const [text, setText] = useState('')
7 const finalText = 'SyntaxUI'
8 const chars = '!<>-_\\/[]{}—=+*^?#________'
9
10 useEffect(() => {
11 let iteration = 0
12 const interval = setInterval(() => {
13 setText((prevText) =>
14 finalText
15 .split('')
16 .map((letter, index) => {
17 if (index < iteration) {
18 return finalText[index]
19 }
20 return chars[Math.floor(Math.random() * chars.length)]
21 })
22 .join(''),
23 )
24
25 if (iteration >= finalText.length) {
26 clearInterval(interval)
27 }
28
29 iteration += 1 / 3
30 }, 30)
31
32 return () => clearInterval(interval)
33 }, [])
34
35 return (
36 <div className="text-2xl font-semibold tabular-nums tracking-tight">
37 <div className="text-center text-red-500">{text}</div>
38 </div>
39 )
40}
41
42export default TextScramble

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected