Saltar al contenido
Skillpedia
Sitios e interfaces (frontend)9,7 mil · #12213

no-use-effect

Qué hace

Esta guía aleja a tu agente de un patrón habitual de React que suele causar errores y renderizados adicionales. Está pensada para desarrolladores que escriben o revisan componentes y hooks de React.

Cuándo usarla

  • ✓Cuando tu agente crea nuevos componentes o hooks de React.
  • ✓Cuando reestructura una llamada existente a useEffect.
  • ✓Cuando una solicitud de cambios añade un useEffect que quieres revisar.

Link de la skill

https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Revisa este componente de React y quita cualquier useEffect que no sea realmente necesario.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La habilidad pregunta primero por qué existe cada efecto y después lo sustituye por el patrón más sencillo que encaje. Entre ellos están calcular valores durante el renderizado, usar una biblioteca de datos para cargar información, gestionar las acciones del usuario en manejadores de eventos y usar un hook concreto para una configuración única real.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

No useEffect

Never call useEffect directly unless the work is a true mount-only sync with an external system and no simpler pattern fits. Prefer a render-time computation, a query or mutation hook, an event handler, or a remount boundary instead.

Workflow

  1. Classify why the effect exists.
  2. Replace it with the narrowest pattern below.
  3. Verify with the project's normal lint, typecheck, and tests.

Replacement Patterns

1. Derive state, do not sync it

Replace useEffect(() => setX(derive(y)), [y]) with inline computation or the project's existing memoization conventions.

const filteredProducts = products.filter((product) => product.inStock);

Smell test: state only mirrors props or other state.

2. Use query or mutation libraries for async work

Replace fetch-in-effect code with the app's data layer.

const productQuery = useQuery({
  queryKey: ["product", productId],
  queryFn: () => fetchProduct(productId),
});

Smell test: the effect fetches, awaits, retries, cancels, or writes async results into local state.

3. Use event handlers for user actions

Do the work where the action happens instead of setting a flag and reacting later.

const handleLike = () => {
  postLike();
};

Smell test: state exists only to trigger an effect, then gets reset.

4. Use useMountEffect for mount-only external sync

Use this only for work that is naturally "set up on mount, clean up on unmount": DOM integration, subscriptions, third-party widgets, and stable singleton bindings.

If the project already has a useMountEffect, use it. If not, add a small wrapper:

import { useEffect } from "react";

export function useMountEffect(effect: () => void | (() => void)) {
  useEffect(effect, []);
}

Prefer changing component structure so the component only mounts once preconditions are satisfied.

Smell test: the effect is a one-time setup or teardown for something outside React.

5. Use key to reset component state

If a component should behave like a fresh instance when an ID or entity changes, remount it from the parent.

return <VideoPlayer key={videoId} videoId={videoId} />;

Smell test: the effect exists only to reset local state when props change.

Review Standard

Treat new direct useEffect usage as a bug by default. Ask which of the five patterns applies. Accept direct useEffect only with explicit justification that the code is a mount-only external sync and that useMountEffect is the intended escape hatch.

Structure React Code This Way

Order component logic like this:

  1. Hooks that read external state or data.
  2. Local state.
  3. Derived values computed during render.
  4. Event handlers.
  5. Early returns.
  6. Render output.

Do not introduce mirrored state just to make an effect possible.

Preguntas frecuentes

¿Cuándo sigue permitido useEffect?

Solo para una sincronización real con un sistema externo que se ejecuta una vez al montar, y únicamente cuando ningún patrón más sencillo encaja.

¿Cambia cómo se comporta mi app?

Pretende mantener el mismo comportamiento, y la guía te pide que después ejecutes tus comprobaciones habituales de lint, tipos y pruebas.

¿Qué es un valor derivado?

Un valor calculado a partir de otros valores durante el renderizado, en lugar de copiarlo en una variable de estado aparte.

Detalles

Descripción original del autor

Avoid direct React `useEffect` usage when writing or reviewing React components and hooks. Use this skill when creating new React code, refactoring existing `useEffect` calls, reviewing PRs that introduce `useEffect`, or when an agent reaches for `useEffect` as a default. Replace effects with derived state, query or mutation libraries, event handlers, `useMountEffect` for mount-only external sync, or `key`-based remounts.

repo: fastrepl/anarlog

Popularidad

Estrellas en GitHub
9,7 mil
Posición en el ranking
#12213
Licencia
MIT
Actualizada
1/11/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas