# usePointerTarget

Pointer position in a component's own world units. Returns null when the pointer is away, so a machine can fall back to its idle behaviour.

> For the complete index, see [llms.txt](https://robocn.dev/llms.txt). A Markdown version of any page is available by appending `.md` to its URL or by sending an `Accept: text/markdown` header.

## Install

```bash
bunx --bun shadcn@latest add https://robocn.dev/r/use-pointer-target.json
```

Registry item: `use-pointer-target` · [`https://robocn.dev/r/use-pointer-target.json`](https://robocn.dev/r/use-pointer-target.json)

## Usage

```tsx
const pointer = usePointerTarget<SVGSVGElement>({
  within: "window",
  toWorld: (unit) => ({ x: unit.x * 132 - 66, y: 104 - unit.y * 118 }),
})

<svg ref={pointer.ref}>…</svg>
```

## API

| name | type | default | description |
| --- | --- | --- | --- |
| `toWorld` | `(unit: Vec2, rect: DOMRect) => Vec2` | — | Maps 0..1 inside the element's box into your units. Values run outside 0..1 once the pointer leaves. |
| `within` | `"element" | "window"` | — | Track only over the element, or anywhere on the page. |
| `persist` | `boolean` | — | Hold the last position after the pointer leaves. |

## Source

- `src/hooks/use-pointer-target.ts`
