38 lines
939 B
TypeScript
Raw Normal View History

2023-06-28 01:12:17 +00:00
import { Box } from '@chakra-ui/react'
import { RainbowText } from './rainbowText'
import React from 'react'
export const TextAnimation1 = props => {
const texts = React.useMemo(() => {
return [
2023-06-27 08:09:21 +00:00
'thingtime',
'vibrant',
'infinite',
2023-06-28 01:12:17 +00:00
'creative',
'powerful',
2023-06-27 08:09:21 +00:00
'magical',
2023-06-28 01:12:17 +00:00
'inspiring',
'love',
'tt'
]
}, [])
const [titleText, setTitleText] = React.useState(texts[0])
React.useEffect(() => {
2023-06-28 01:12:17 +00:00
const newTimeout = Math.random() * 1500 + 2500
2023-06-27 08:09:21 +00:00
setTimeout(() => {
2023-06-28 01:12:17 +00:00
// let newTextIdx = Math.round(Math.random() * (texts.length - 1))
let newTextIdx = texts?.indexOf(titleText) + 1
// if (newTextIdx === texts.indexOf(titleText)) {
// newTextIdx = newTextIdx + 1
// }
const newText = texts[newTextIdx] || texts[0]
setTitleText(newText)
2023-06-27 08:09:21 +00:00
}, newTimeout)
}, [titleText, texts])
return <RainbowText>{titleText}</RainbowText>
}