Skip to Content
HooksuseResizable

useResizable

useResizable enables drag-to-resize behavior on any element. The user drags a handle element (typically a bottom-right grip) to resize the target.

Options

OptionTypeDefaultDescription
containerHTMLElement | nullnullBoundary element. When null, constrains to the viewport.
resizablebooleantrueEnable or disable resizing.
minWidthnumber200Minimum width in px.
minHeightnumber120Minimum height in px.
maxWidthnumberunlimitedMaximum width in px.
maxHeightnumberunlimitedMaximum height in px.
onResizeChange(resizing: boolean) => void-Callback when resize starts or stops.

Returns

FieldTypeDescription
resizingbooleanWhether the element is currently being resized.
setTargetRef(el: TTarget | null) => voidRef callback for the element that will be resized.
setResizeRef(el: THandle | null) => voidRef callback for the resize handle element.
resetSize() => voidReset size to the initial state (removes inline width/height).
sizeRefRefObject<Size>Internal { width, height } state.

Usage

import { useResizable } from '@murasaki-io/react98' function ResizablePanel() { const { setTargetRef, setResizeRef, resizing } = useResizable<HTMLDivElement>({ resizable: true, minWidth: 200, minHeight: 100, }) return ( <div ref={setTargetRef} style={{ width: 400, height: 300 }}> <p>Panel content</p> <div ref={setResizeRef} className="cursor-nwse-resize">⊿</div> </div> ) }

Behavior

  • A 3 px movement threshold prevents accidental resizes from clicks.
  • When the container is smaller than minWidth/minHeight, the element is allowed to overflow rather than being forced below its minimum size.
  • The body cursor is set to nwse-resize during resize to prevent flicker.
  • The stored size is re-applied when the target re-mounts (e.g. after minimize/restore).
Last updated on