Created
March 13, 2019 20:22
-
-
Save konsumer/afb3140c9b2c59adbee358aef55aa5ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react' | |
import { render, Box } from 'ink' | |
import Gradient from 'ink-gradient' | |
import BigText from 'ink-big-text' | |
const useCounter = () => { | |
const [counter, setCounter] = useState(0) | |
let i | |
useEffect(() => { | |
i = setInterval(() => { | |
setCounter(c => c + 1) | |
}, 500) | |
}, () => { | |
clearInterval(i) | |
}) | |
return [counter, setCounter] | |
} | |
const Counter = () => { | |
const [counter] = useCounter() | |
return ( | |
<Box height={50} flexShrink={0} flexGrow={1} alignItems='center' justifyContent='center'> | |
<Gradient name='rainbow'> | |
<BigText text={`${counter} unicorns`} /> | |
</Gradient> | |
</Box> | |
) | |
} | |
render(<Counter />) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment