on 04765bb help sign in
bridge/src/components/Blinky.js
31 lines 761 B history raw
1import React, { useState, useRef } from 'react';
3import useInterval from 'lib/useInterval';
5// TODO: make these characters display as the same width
6export const kLoadingCharacter = '▓';
7export const kInterstitialCharacter = '░';
8const kBlinkAfterMs = 2500; // ms
10export const matchBlinky = obj =>
11 obj.matchWith({
12 Nothing: () => <Blinky />,
13 Just: p => p.value,
14 });
16export default function Blinky({
17 a = kLoadingCharacter,
18 b = kInterstitialCharacter,
19}) {
20 const [value, setValue] = useState(true);
21 const now = useRef(new Date());
23 useInterval(() => {
24 // only start blinking if we've elapsed enough time
25 if (new Date() - now.current > kBlinkAfterMs) {
26 setValue(val => !val);
27 }
28 }, 1000);
30 return value ? a : b;