useEventTarget
A hook that encapsulates onChange and value logic for form controls that obtains value through event.target.value. It also supports custom transformer and reset functionalities.
Overview
A hook that encapsulates onChange and value logic for form controls that obtains value through event.target.value. It also supports custom transformer and reset functionalities.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.jsonA hook that encapsulates onChange and value logic for form controls that obtains value through event.target.value. It also supports custom transformer and reset functionalities.
Example
Basic Usage
Custom transformer
API
const [value, { onChange, reset }] = useEventTarget<T, U>(Options<T, U>);Result
| Property | Description | Type |
| -- | - | -- | - |
| initialValue | initial value | T | - |
| transformer | custom transform function applied to value | (value: U) => T | - |