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
/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settingsWhat 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-settings2Manually: put the files in place
.claude/rules/ui-measure-views.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/ui-measure-views.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/ui-measure-views.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/ui-measure-views.mdManually: put the files in place
.clinerules/ui-measure-views.mdStep 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