aboutsummaryrefslogtreecommitdiffstats
path: root/components/Loader.jsx
blob: 1804502e71988d3c9defa54f2ddbd44eeb4f9c51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Text } from 'react-native'
import { useState, useEffect } from "react"

const Loader = ({ style = {}, text = 'Loading...' }) => {
  const [nr, setNr] = useState(0)

  useEffect(() => {
    const timer = setTimeout(() => {
      nr < text.length
        ? setNr(nr+1)
        : clearTimeout(timer)
    }, 50);

    return () => clearTimeout(timer);
  });

  return <Text style={{ color: 'grey', ...style }}>{text.substring(0, nr)}</Text>
}

export default Loader