react-use-callback

Teach correct useCallback usage to prevent unnecessary React re-renders.

280|36|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/flpbalada/my-opencode-config --skill react-use-callback
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-use-callback
Source: https://github.com/flpbalada/my-opencode-config/tree/main/skills/react-use-callback
Command: npx skills add https://github.com/flpbalada/my-opencode-config --skill react-use-callback

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill solves unnecessary re-renders by teaching correct use of the useCallback hook in React.

Core Features & Use Cases

It applies to scenarios where callbacks are passed to memoized children, used as effect dependencies, or returned from custom hooks.

Quick Start

Create a simple React component that uses useCallback to memoize a click handler dependent on itemId and passes it to a memoized child.

Frequently Asked Questions about react-use-callback

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent unnecessary re-renders when passing callbacks to memoized child components in React?

To prevent unnecessary re-renders in React, use the useCallback hook to stabilize callback references passed to memoized children. This ensures the callback identity remains consistent across renders unless its dependencies change, avoiding child re-renders.

When should I use useCallback for dependency management in React effects?

Use useCallback for dependency management in React effects when a callback is used as an effect dependency. Stabilizing the callback reference prevents the effect from re-running on every render due to a new function identity being created.

What is the best way to return stable callbacks from custom hooks in React?

The best way to return stable callbacks from custom React hooks is wrapping the returned function with useCallback. This memoizes the callback, minimizing dependencies for consumers and avoiding stale references while maintaining consistent behavior.

Why does my memoized child component still re-render even though I am using useCallback?

Your memoized child component re-renders because the useCallback dependency array likely includes values that change every render. Correct dependency management requires including only the variables the callback actually uses to maintain a stable reference.

What are common anti-patterns when stabilizing callbacks with useCallback in React?

Common useCallback anti-patterns in React include omitting dependencies to create stable references artificially, which causes stale references, and overusing memoization on callbacks that are never passed to memoized children, adding overhead without benefit.

Can I use useCallback to optimize performance for all click handlers in React?

You can use useCallback for click handlers in React, but it is not always beneficial. Performance optimization is achieved when the stabilized callback is passed to a memoized child; otherwise, useCallback adds unnecessary overhead without preventing re-renders.