Skip to main content
rule CX Codex

ui-measure-views — Claude Code rule: what it does, how to install

ui-measure-views guides agents to measure React Native view dimensions using useLayoutEffect alongside onLayout without triggering unneeded re-renders.

MIT ★ 1,216 updated 2026-10-24

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settings
Open on GitHub

What ui-measure-views does

This rule defines how an assistant should measure React Native components. It pairs useLayoutEffect for immediate measurement on mount with onLayout to capture subsequent layout changes. For React Native 0.82 and newer, it calls getBoundingClientRect(), falling back to measure() on earlier releases.

When storing both width and height as an object, the rule enforces a functional state updater. Comparing incoming layout values against the previous state prevents rerendering when dimensions remain identical. Reading state directly inside the callback is avoided.

What it helps with

  • get immediate React Native view dimensions on mount
  • track dynamic layout updates without superfluous re-renders
  • support view measurements across React Native 0.82+ and older versions

Example prompts for the agent

  • Create a React Native container that measures both width and height without duplicate renders
  • Implement a box component measuring its height synchronously on mount

How to install ui-measure-views

1Plugin marketplace

/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settings

2Manually: put the files in place

.claude/rules/ui-measure-views.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about ui-measure-views

How to install ui-measure-views in Claude Code?

Run /plugin marketplace add fcakyon/claude-codex-settings, then execute /plugin install react-skills@claude-settings.

What does ui-measure-views do?

It guides the assistant to measure React Native views synchronously on mount via useLayoutEffect and handle updates through onLayout.

How does it avoid unnecessary re-renders?

It uses functional state updates to compare new width and height values against previous ones, returning the existing state object when sizes match.

Source text

ui-measure-views.md · MIT
---
title: Measuring View Dimensions
impact: MEDIUM
impactDescription: synchronous measurement, avoid unnecessary re-renders
tags: layout, measurement, onLayout, useLayoutEffect
---

## Measuring View Dimensions

Use both `useLayoutEffect` (synchronous) and `onLayout` (for updates). The sync
measurement gives you the initial size immediately; `onLayout` keeps it current
when the view changes. For non-primitive states, use a dispatch updater to
compare values and avoid unnecessary re-renders.

**Height only:**

```tsx
import { useLayoutEffect, useRef, useState } from 'react'
import { View, LayoutChangeEvent } from 'react-native'

function MeasuredBox({ children }: { children: React.ReactNode }) {
  const ref = useRef<View>(null)
  const [height, setHeight] = useState<number | undefined>(undefined)

  useLayoutEffect(() => {
    // Sync measurement on mount (RN 0.82+)
    const rect = ref.current?.getBoundingClientRect()
    if (rect) setHeight(rect.height)
    // Pre-0.82: ref.current?.measure((x, y, w, h) => setHeight(h))
  }, [])

  const onLayout = (e: LayoutChangeEvent) => {
    setHeight(e.nativeEvent.layout.height)
  }

  return (
    <View ref={ref} onLayout={onLayout}>
      {children}
    </View>
  )
}
```

**Both dimensions:**

```tsx
import { useLayoutEffect, useRef, useState } from 'react'
import { View, LayoutChangeEvent } from 'react-native'

type Size = { width: number; height: number }

function MeasuredBox({ children }: { children: React.ReactNode }) {
  const ref = useRef<View>(null)
  const [size, setSize] = useState<Size | undefined>(undefined)

  useLayoutEffect(() => {
    const rect = ref.current?.getBoundingClientRect()
    if (rect) setSize({ width: rect.width, height: rect.height })
  }, [])

  const onLayout = (e: LayoutChangeEvent) => {
    const { width, height } = e.nativeEvent.layout
    setSize((prev) => {
      // for non-primitive states, compare values before firing a re-render
      if (prev?.width === width && prev?.height === height) return prev
      return { width, height }
    })
  }

  return (
    <View ref={ref} onLayout={onLayout}>
      {children}
    </View>
  )
}
```

Use functional setState to compare—don't read state directly in the callback.

© fcakyon · MIT · fcakyon/claude-codex-settings

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set113

The whole set →
animation-gpu-properties animation-gpu-properties — a rule that keeps animations off width, height, top, left, margin and padding and moves them onto transform and opacity, so no layout pass runs per frame. CX Codex +1 ★ 1,216repo stars rerender-no-inline-components The rerender-no-inline-components rule flags React components declared inside other components, a pattern that causes remounts on parent renders. Use it when state, focus, or scroll position keeps resetting. CX Codex +1 ★ 1,216repo stars state-ground-truth state-ground-truth — a rule that stops agents from storing derived visual values in state. Keeps React and Reanimated logic centered on facts. CX Codex +1 ★ 1,216repo stars ui-styling ui-styling enforces modern React Native styling practices: smooth continuous borders, gap spacing, CSS boxShadow syntax, and native gradients. CX Codex +1 ★ 1,216repo stars create-issue create-issue is a Claude Code skill for drafting or revising issues about bugs and missing features. It can also refine an issue title or body before publication. CX Codex +1 ★ 1,216repo stars list-performance-item-memo list-performance-item-memo — a rule for React list rows: split the item into primitive props so memo() can compare them shallowly and skip a render when nothing changed. CX Codex +1 ★ 1,216repo stars react-state-dispatcher react-state-dispatcher enforces functional dispatch updaters in React setState calls whenever state depends on current values. Prevents stale closures in callbacks. CX Codex +1 ★ 1,216repo stars setup Skill for Claude Code configures real integration testing and user QA journeys across project codebases. It triggers when asked to set up QA or generate end-to-end testing flows. CX Codex +1 ★ 1,216repo stars

Project sponsors

Companies that keep this analytics open