shadcn-ahooks

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.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useEventTarget.json

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.

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 | - |

On this page