React Hook Example
React Hook Example
Here's a simple React hook for managing state:
import { useState } from 'react'
function useCounter(initialCount = 0) {
const [count, setCount] = useState(initialCount)
const increment = () => setCount((prev) => prev + 1)
const decrement = () => setCount((prev) => prev - 1)
const reset = () => setCount(initialCount)
return { count, increment, decrement, reset }
}