old.nicco.io/screens/Letters.tsx

38 lines
790 B
TypeScript
Raw Normal View History

2019-03-03 16:13:57 +01:00
import React, { useEffect, useRef, useState } from 'react'
2020-01-05 17:34:49 +01:00
import LetterAnimation from '../components/LetterAnimation'
import '../styles/Letters.styl'
2019-03-03 16:13:57 +01:00
type Pair = [string, string]
const pairs: Pair[] = [
['visualize', 'create'],
['invision', 'build'],
['ideate', 'deploy'],
]
export const Duration = 4000
const Letters: React.FC = React.memo(() => {
const [index, setIndex] = useState<number>(0)
const wrapper = useRef<HTMLElement>(null)
useEffect(() => {
setTimeout(
() => setIndex((index < pairs.length - 1) ? index + 1 : 0),
Duration,
)
}, [index])
return <span id={'letters-wrapper'} ref={wrapper}>
2020-01-05 17:34:49 +01:00
<LetterAnimation text={pairs[index][0] + '.'} />
<br />
<LetterAnimation text={pairs[index][1] + '.'} delay={500} />
2019-03-03 16:13:57 +01:00
</span>
})
export default Letters