RE

rerender-lazy-state

Uses the functional form of useState to run initial state calculations only once.

Install

mkdir -p .claude/skills/rerender-lazy-state && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5328" && unzip -o skill.zip -d .claude/skills/rerender-lazy-state && rm skill.zip

Installs to .claude/skills/rerender-lazy-state

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Use lazy state initialization with useState function form. Apply when computing expensive initial values like building search indexes, parsing JSON, or complex calculations.
173 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Enforces lazy initialization patterns for costly functions
  • Prevents redundant execution during component re-renders
  • Optimizes state updates for large JSON parsing
  • Scopes initialization logic specifically to mounting

How it works

Wraps the initializer in a functional factory provided to useState to defer execution until the first render.

Inputs & outputs

You give it
Expensive function or state initial value
You get back
Refactored React code with useState function form

When to use rerender-lazy-state

  • Parsing large JSON from localStorage
  • Building search indexes on component mount
  • Initializing heavy data structures

About this skill

Use Lazy State Initialization

Pass a function to useState for expensive initial values. Without the function form, the initializer runs on every render even though the value is only used once.

Incorrect (runs on every render):

function FilteredList({ items }: { items: Item[] }) {
  // buildSearchIndex() runs on EVERY render, even after initialization
  const [searchIndex, setSearchIndex] = useState(buildSearchIndex(items))
  const [query, setQuery] = useState('')

  // When query changes, buildSearchIndex runs again unnecessarily
  return <SearchResults index={searchIndex} query={query} />
}

function UserProfile() {
  // JSON.parse runs on every render
  const [settings, setSettings] = useState(
    JSON.parse(localStorage.getItem('settings') || '{}')
  )

  return <SettingsForm settings={settings} onChange={setSettings} />
}

Correct (runs only once):

function FilteredList({ items }: { items: Item[] }) {
  // buildSearchIndex() runs ONLY on initial render
  const [searchIndex, setSearchIndex] = useState(() => buildSearchIndex(items))
  const [query, setQuery] = useState('')

  return <SearchResults index={searchIndex} query={query} />
}

function UserProfile() {
  // JSON.parse runs only on initial render
  const [settings, setSettings] = useState(() => {
    const stored = localStorage.getItem('settings')
    return stored ? JSON.parse(stored) : {}
  })

  return <SettingsForm settings={settings} onChange={setSettings} />
}

Use lazy initialization when computing initial values from localStorage/sessionStorage, building data structures (indexes, maps), reading from the DOM, or performing heavy transformations.

For simple primitives (useState(0)), direct references (useState(props.value)), or cheap literals (useState({})), the function form is unnecessary.

When not to use it

  • Simple primitives like strings, numbers, or booleans
  • Cheap calculations that execute quickly on every render

Prerequisites

React frameworkBasic understanding of component lifecycle

Limitations

  • Only beneficial for high-compute initialization
  • Does not impact subsequent update performance

How it compares

It explicitly moves logic out of the component body to avoid repeat execution compared to direct function calls.

Compared to similar skills

rerender-lazy-state side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
rerender-lazy-state (this skill)16moNo flagsIntermediate
nextjs-developer3282moNo flagsAdvanced
screenshot-to-code2042moNo flagsBeginner
zustand1132moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

nextjs-developer

zenobi-us

Expert Next.js developer mastering Next.js 14+ with App Router and full-stack features. Specializes in server components, server actions, performance optimization, and production deployment with focus on building fast, SEO-friendly applications.

328531

screenshot-to-code

OneWave-AI

Convert UI screenshots into working HTML/CSS/React/Vue code. Detects design patterns, components, and generates responsive layouts. Use this when users provide screenshots of websites, apps, or UI designs and want code implementation.

204389

zustand

lobehub

Zustand state management guide. Use when working with store code (src/store/**), implementing actions, managing state, or creating slices. Triggers on Zustand store development, state management questions, or action implementation.

113434

web-artifacts-builder

anthropics

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

49162

landing-page-guide-v2

bear2u

Create distinctive, high-converting landing pages that combine proven conversion elements with exceptional design quality. Build beautiful, memorable landing pages using Next.js 14+ and ShadCN UI that avoid generic AI aesthetics while following the 11 essential elements framework.

48105

senior-fullstack

davila7

Comprehensive fullstack development skill for building complete web applications with React, Next.js, Node.js, GraphQL, and PostgreSQL. Includes project scaffolding, code quality analysis, architecture patterns, and complete tech stack guidance. Use when building new projects, analyzing code quality, implementing design patterns, or setting up development workflows.

35110

Search skills

Search the agent skills registry