Last active
March 16, 2023 23:07
-
-
Save D-Maher/a6a13bf1da9de92e6da38f7dc060acd6 to your computer and use it in GitHub Desktop.
Custom React hook
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 { useState } from "react"; | |
function useCounter( | |
initialCount: number = 0 | |
): [number, () => void, () => void] { | |
const [count, setCount] = useState<number>(initialCount); | |
function increment() { | |
setCount(count + 1); | |
} | |
function decrement() { | |
setCount(count - 1); | |
} | |
return [count, increment, decrement]; | |
} | |
export default useCounter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment