rendering-usetransition-loading — Claude Code rule: what it does
rendering-usetransition-loading — a rule that swaps hand-rolled loading flags in React components for useTransition. Useful when a spinner runs on its own useState.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/rendering-usetransition-loading.mdWhat rendering-usetransition-loading does
The rule pushes you off a manual isLoading flag and onto React's useTransition. It carries two snippets side by side: a search box flipping setIsLoading around an await, and the same box driven by isPending with startTransition.
Pending state clears itself when a transition throws, which a hand-written flag does not do. A newer transition cancels the one still in flight, so fast typing leaves no orphaned spinner. The input updates at once and the result list catches up.
It ships as a markdown file, no scripts attached. Nothing happens outside React code, because useTransition comes from React.
What it helps with
- replace manual
setIsLoadingcalls in a search component - tie the spinner to
isPendinginstead of local state - drop stale spinners when a new request starts
- keep the input responsive while results load
- clear loading state after a failed transition
Example prompts for the agent
- Rewrite
SearchResultswithuseTransitionand drop the manualisLoadingflag. - Find components calling
setIsLoadingand show theisPendingversion. - The spinner sticks after a failed fetch — walk through
rendering-usetransition-loadingand fix it.
How to install rendering-usetransition-loading
Manually: put the files in place
.claude/rules/rendering-usetransition-loading.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/rendering-usetransition-loading.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/rendering-usetransition-loading.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/rendering-usetransition-loading.mdManually: put the files in place
.clinerules/rendering-usetransition-loading.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about rendering-usetransition-loading
How to install rendering-usetransition-loading in Claude Code?
Add the file .claude/rules/rendering-usetransition-loading.md to your project and paste the rule text into it.
What does rendering-usetransition-loading do?
It moves loading state onto useTransition: isPending drives the spinner, and result updates run inside startTransition.
Does the rule only apply to React?
Yes. useTransition is a React hook, so the advice has nothing to act on in another framework.
Source text
rendering-usetransition-loading.md · MIT
---
title: Use useTransition Over Manual Loading States
impact: LOW
impactDescription: reduces re-renders and improves code clarity
tags: rendering, transitions, useTransition, loading, state
---
## Use useTransition Over Manual Loading States
Use `useTransition` instead of manual `useState` for loading states. This provides built-in `isPending` state and automatically manages transitions.
**Incorrect (manual loading state):**
```tsx
function SearchResults() {
const [query, setQuery] = useState('')
const [results, setResults] = useState([])
const [isLoading, setIsLoading] = useState(false)
const handleSearch = async (value: string) => {
setIsLoading(true)
setQuery(value)
const data = await fetchResults(value)
setResults(data)
setIsLoading(false)
}
return (
<>
<input onChange={(e) => handleSearch(e.target.value)} />
{isLoading && <Spinner />}
<ResultsList results={results} />
</>
)
}
```
**Correct (useTransition with built-in pending state):**
```tsx
import { useTransition, useState } from 'react'
function SearchResults() {
const [query, setQuery] = useState('')
const [results, setResults] = useState([])
const [isPending, startTransition] = useTransition()
const handleSearch = (value: string) => {
setQuery(value) // Update input immediately
startTransition(async () => {
// Fetch and update results
const data = await fetchResults(value)
setResults(data)
})
}
return (
<>
<input onChange={(e) => handleSearch(e.target.value)} />
{isPending && <Spinner />}
<ResultsList results={results} />
</>
)
}
```
**Benefits:**
- **Automatic pending state**: No need to manually manage `setIsLoading(true/false)`
- **Error resilience**: Pending state correctly resets even if the transition throws
- **Better responsiveness**: Keeps the UI responsive during updates
- **Interrupt handling**: New transitions automatically cancel pending ones
Reference: [useTransition](https://react.dev/reference/react/useTransition)
© tech-leads-club · MIT · tech-leads-club/agent-skills