@rbxts/pretty-react-hooks
Version:
Useful hooks for @rbxts/react
34 lines (23 loc) • 637 B
Markdown
```ts
function useMouse(listener?: (mouse: Vector2) => void): Binding<Vector2>;
```
Returns a binding to the position of the mouse.
If a listener is provided, it will be called when the mouse moves and once on mount.
- `listener` - An optional listener to be called when the mouse moves.
- The position of the mouse in pixels.
```tsx
function MouseTracker() {
const mouse = useMouse();
return (
<frame
AnchorPoint={Vector2.new(1, 1)}
Size={UDim2.fromOffset(16, 16)}
Position={mouse.map((p) => UDim2.fromOffset(p.X, p.Y))}
/>
);
}
```