Created
March 27, 2019 20:09
-
-
Save isacjunior/66a79a0f3ac3667d1f8c97049d3390a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 } from 'react' | |
interface Props { | |
initialState: number, | |
step: number | |
} | |
function useCounter({ initialState, step }: Props) { | |
const [count, setCount] = useState(initialState) | |
const increment = () => setCount(count + step) | |
return { count, increment } | |
} | |
function Counter() { | |
const { count, increment } = useCounter({ initialState: 0, step: 1 }) | |
return <button onClick={increment}>{count}</button> | |
} | |
export default Counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment