Skip to main content
rule CX Codex

rerender-no-inline-components — Claude Code rule

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.

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 rerender-no-inline-components does

A component declared inside another component gets a new type whenever its parent renders. React then unmounts the old instance and mounts a new one, which can discard state and recreate DOM nodes. Inputs may lose focus, animations can restart, and scroll position may reset.

The rule points toward moving child components to the top level and passing the values they need as props. In its example, Avatar and Stats receive their data from UserProfile. That keeps their component types stable across parent renders.

For Claude Code, the rule is part of react-skills. It concerns React component structure, so projects without React have no use for this check. The listed installation steps target Claude Code; Codex has no install command in the provided commands.

What it helps with

  • spot components declared inside another component
  • stop inputs from losing focus on parent renders
  • preserve child component state between renders
  • trace animations or scroll resets to remounts

Example prompts for the agent

  • Review UserProfile and find any components declared inside it; suggest moving them outside.
  • Find why this React input loses focus whenever its parent renders.
  • Check whether a component declared inside its parent is being remounted and losing state.

How to install rerender-no-inline-components

1Plugin marketplace

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

2Manually: put the files in place

.claude/rules/rerender-no-inline-components.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 rerender-no-inline-components

How do I install rerender-no-inline-components in Claude Code?

Run /plugin marketplace add fcakyon/claude-codex-settings, then /plugin install react-skills@claude-settings. The rule file is .claude/rules/rerender-no-inline-components.md.

What does rerender-no-inline-components do?

It flags React components declared inside other components. Their type changes on each parent render, so React remounts them and can discard state or recreate DOM nodes.

Why does an input lose focus when its parent renders?

A component declared inside its parent is one possible cause: React treats it as a new type and remounts it. The rule recommends moving that component to the top level and passing its values as props.

Source text

rerender-no-inline-components.md · MIT
---
title: Don't Define Components Inside Components
impact: HIGH
impactDescription: prevents remount on every render
tags: rerender, components, remount, performance
---

## Don't Define Components Inside Components

**Impact: HIGH (prevents remount on every render)**

Defining a component inside another component creates a new component type on every render. React sees a different component each time and fully remounts it, destroying all state and DOM.

A common reason developers do this is to access parent variables without passing props. Always pass props instead.

**Incorrect (remounts on every render):**

```tsx
function UserProfile({ user, theme }) {
  // Defined inside to access `theme` - BAD
  const Avatar = () => (
    <img
      src={user.avatarUrl}
      className={theme === 'dark' ? 'avatar-dark' : 'avatar-light'}
    />
  )

  // Defined inside to access `user` - BAD
  const Stats = () => (
    <div>
      <span>{user.followers} followers</span>
      <span>{user.posts} posts</span>
    </div>
  )

  return (
    <div>
      <Avatar />
      <Stats />
    </div>
  )
}
```

Every time `UserProfile` renders, `Avatar` and `Stats` are new component types. React unmounts the old instances and mounts new ones, losing any internal state, running effects again, and recreating DOM nodes.

**Correct (pass props instead):**

```tsx
function Avatar({ src, theme }: { src: string; theme: string }) {
  return (
    <img
      src={src}
      className={theme === 'dark' ? 'avatar-dark' : 'avatar-light'}
    />
  )
}

function Stats({ followers, posts }: { followers: number; posts: number }) {
  return (
    <div>
      <span>{followers} followers</span>
      <span>{posts} posts</span>
    </div>
  )
}

function UserProfile({ user, theme }) {
  return (
    <div>
      <Avatar src={user.avatarUrl} theme={theme} />
      <Stats followers={user.followers} posts={user.posts} />
    </div>
  )
}
```

**Symptoms of this bug:**
- Input fields lose focus on every keystroke
- Animations restart unexpectedly
- `useEffect` cleanup/setup runs on every parent render
- Scroll position resets inside the component

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

Similar IDE rules

All IDE rules for Frontend and UI →
rerender-simple-expression-in-memo tech-leads-club The rerender-simple-expression-in-memo rule advises against using useMemo for simple expressions that return a boolean, number, or string. It applies when reviewing React component calculations. CX Codex +1 ★ 7,191repo stars rerender-derived-state-no-effect tech-leads-club The rerender-derived-state-no-effect rule keeps derived values out of React state and avoids effects that mirror props. Use it when reviewing components for extra renders and state drift. CX Codex +1 ★ 7,191repo stars rerender-derived-state jarrodwatts The rerender-derived-state rule favors derived boolean state over continuously changing values, reducing React re-renders. It fits responsive UI logic. CX Codex +1 ★ 1,064repo stars design-system-compound-components alexj11324 design-system-compound-components is a Claude Code rule that forbids raw string children in non-text components. It enforces compound structures like ButtonText and ButtonIcon across the design system. CX Codex +1 ★ 88repo stars sort-components rerun-build The sort-components Claude Code skill sorts UI components into folders by feature. It activates when adding a component or reorganizing apps/ui/components/. CX Codex +1 ★ 1,120repo stars animation-components Claude Design Skillstack animation-components — a Claude Code plugin that brings together animation and UI component libraries for React work. Use it when a screen needs motion effects or ready-made animated elements. ★ 1,428repo stars

From the same set113

The whole set →
paper-search-usage paper-search-usage guides coding agents to query academic databases, fetch citation graphs, and download research papers via Paper Search CLI. CX Codex +1 1installs setup setup guides the agent through installing and debugging Paper Search CLI. Replaces Docker MCP with direct CLI calls for paper search and DOI lookup. CX Codex +1 ★ 1,216repo stars review-pr The review-pr skill checks pull requests for bugs, regressions, risky changes, and missing tests. Use it to get a focused list of issues before approving a PR. CX Codex +1 ★ 1,216repo stars 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 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 ui-measure-views ui-measure-views guides agents to measure React Native view dimensions using useLayoutEffect alongside onLayout without triggering unneeded re-renders. 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

Project sponsors

Companies that keep this analytics open