8-bit-pixel-art-patter…
Create pixelated borders, shadows, and effects for 8-bit retro components. Apply when building 8-bit styled UI components that…
Use functional setState updates to prevent stale closures and unnecessary callback recreations. Apply when updating state based on the current state value in React components.
Claude Code
$ npx -y skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate --agent claude-code
Codex
$ npx skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate -a codex -y
Cursor
$ npx skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate -a cursor -y
Gemini CLI
$ npx skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate -a gemini-cli -y
GitHub Copilot
$ npx skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate -a github-copilot -y
OpenCode
$ npx skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate -a opencode -y
Windsurf
$ npx skills add theorcdev/8bitcn-ui --skill rerender-functional-setstate -a windsurf -y
name: rerender-functional-setstate description: Use functional setState updates to prevent stale closures and unnecessary callback recreations. Apply when updating state based on the current state value in React components.
When updating state based on the current state value, use the functional update form of setState instead of directly referencing the state variable. This prevents stale closures, eliminates unnecessary dependencies, and creates stable callback references.
**Incorrect (requires state as dependency):**
function TodoList() {
const [items, setItems] = useState(initialItems)
// Callback must depend on items, recreated on every items change
const addItems = useCallback((newItems: Item[]) => {
setItems([...items, ...newItems])
}, [items]) // items dependency causes recreations
// Risk of stale closure if dependency is forgotten
const removeItem = useCallback((id: string) => {
setItems(items.filter(item => item.id !== id))
}, []) // Missing items dependency - will use stale items!
return <ItemsEditor items={items} onAdd={addItems} onRemove={removeItem} />
}The first callback is recreated every time `items` changes, which can cause child components to re-render unnecessarily. The second callback has a stale closure bug—it will always reference the initial `items` value.
**Correct (stable callbacks, no stale closures):**
function TodoList() {
const [items, setItems] = useState(initialItems)
// Stable callback, never recreated
const addItems = useCallback((newItems: Item[]) => {
setItems(curr => [...curr, ...newItems])
}, []) // No dependencies needed
// Always uses latest state, no stale closure risk
const removeItem = useCallback((id: string) => {
setItems(curr => curr.filter(item => item.id !== id))
}, []) // Safe and stable
return <ItemsEditor items={items} onAdd={addItems} onRemove={removeItem} />
}**Benefits:**
1. **Stable callback references** - Callbacks don't need to be recreated when state changes 2. **No stale closures** - Always operates on the latest state value 3. **Fewer dependencies** - Simplifies dependency arrays and reduces memory leaks 4. **Prevents bugs** - Eliminates the most common source of React closure bugs
**When to use functional updates:**
**When direct updates are fine:**
**Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, the compiler can automatically optimize some cases, but functional updates are still recommended for correctness and to prevent stale closure bugs.
Accessible retro components that you can copy and paste into your apps.Free. Open Source. Built on shadcn/ui. Documentation · Components · Blocks · Themes · Discord
Create pixelated borders, shadows, and effects for 8-bit retro components. Apply when building 8-bit styled UI components that…
Create documentation with gaming-specific examples, retro styling, and 8-bit terminology. Apply when documenting gaming blocks,…
Optimize 8-bit animations for smooth performance. Apply when creating animated pixel art, game UI effects, or any retro-styled…
Import directly from source files instead of barrel files. Apply when using libraries like lucide-react, @mui/material, or…
Use next/dynamic for lazy-loading heavy components. Apply when importing large components like editors, charts, or rich text…
Best practices for wrapping shadcn/ui components. Apply when creating 8-bit styled variants of existing shadcn/ui components.
Migrates React projects and components from Radix UI to Base UI. Use when asked to migrate from radix, move to base-ui, convert…
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One…