@rbxts/pretty-react-hooks
Version:
Useful hooks for @rbxts/react
31 lines (20 loc) • 644 B
Markdown
```ts
function useViewport(listener?: (viewport: Vector2) => void): Binding<Vector2>;
```
Returns a binding to the size of the viewport.
If a listener is provided, it will be called when the viewport changes and once on mount.
- `listener` - An optional listener to be called when the viewport size changes.
- The size of the viewport in pixels.
```tsx
function TextSize() {
const viewport = useViewport();
const textSize = viewport.map((size) => {
return math.min(size.X / 1920, size.Y / 1080) * 14;
});
return <text TextSize={textSize} />;
}
```