gridland
Hooks

useTerminalDimensions

Get the current terminal dimensions

The useTerminalDimensions hook returns the current terminal dimensions in columns and rows. It automatically updates when the terminal is resized.

Import
import { useTerminalDimensions } from "@gridland/utils"

Usage

Basic
function MyComponent() {
  const { width, height } = useTerminalDimensions()

  return (
    <text>Terminal is {width}x{height}</text>
  )
}
Responsive layout
function ResponsiveLayout() {
  const { width } = useTerminalDimensions()

  if (width < 60) {
    return <NarrowLayout />
  }
  return <WideLayout />
}

Returns

PropertyTypeDescription
widthnumberTerminal width in columns
heightnumberTerminal height in rows

On this page