Skip to content

use_rects

API

counterweight.hooks.use_rects

use_rects() -> Rects
RETURNS DESCRIPTION
Rects

A recording describing the rectangular areas of the content, padding, border, and margin of the calling component's top-level element on the previous render cycle. In the initial render, the returned rectangles will all be positioned at the top-left corner of the screen with 0 width and height.

counterweight.hooks.Rects dataclass

Rects(
    content: Rect, padding: Rect, border: Rect, margin: Rect
)

content instance-attribute

content: Rect

padding instance-attribute

padding: Rect

border instance-attribute

border: Rect

margin instance-attribute

margin: Rect

Use use_hovered for detecting hover state

use_rects is a low-level hook. For the common use case of detecting whether the mouse is hovering over an element, use the higher-level use_hovered hook instead.

This is not a stateful hook

use_rects is not a stateful hook: it does not use use_state under the hood. That means that if the dimensions of the component's top-level element change in a way that is not connected to some other state change (e.g., if a sibling component changes size), using this hook will not cause the component to re-render.