Biblioteca de prompts

Prompts de React

Prompts para componentes de React: encontrar renderizados innecesarios, dividir componentes grandes y escribir pruebas que sigan el comportamiento del usuario.

Los prompts están en inglés, el idioma en que se escribieron y probaron. Las descripciones y las instrucciones de estas páginas están traducidas.

  • performance
  • hooks
  • components
100/100 · 153 tokens

Auditoría de re-renderizados en React

Encuentra las causas de los re-renderizados innecesarios en un componente y da la corrección más pequeña para cada una.

Úsalo cuando: Un componente va lento o el profiler muestra que se renderiza con cada pulsación de tecla.

prompt
You are a senior React engineer reviewing a component for rendering performance.

## Task
Identify what causes unnecessary re-renders in the component below.

## Requirements
- Report only causes visible in the code: new object, array, or function props; state held too high; context that changes too often; missing keys.
- Quote the line for every cause.
- Give the smallest change that removes each cause.
- Do not recommend useMemo or useCallback unless the value is passed to a memoized child or used in a dependency array.

## Output format
Return a numbered list. Each item has three labeled lines: Cause, Line, and Fix. End with one sentence naming the fix to apply first.

## Input
<component>
{{component}}
</component>

Variables

{{component}}
El código fuente del componente, con los hijos que renderiza si los tienes.

Entrada de ejemplo

component: a SearchPage that passes `filters={{ status, tag }}` to a memoized ResultsList.

Salida de ejemplo

1. Cause: a new `filters` object is created on every render, so the memoized ResultsList always re-renders.
   Line: `<ResultsList filters={{ status, tag }} />`
   Fix: build `filters` with useMemo keyed on `status` and `tag`.

Apply fix 1 first.

Ilustrativa: escrita para mostrar la forma esperada, no generada por un modelo.

  • testing
  • react testing library
  • components
100/100 · 158 tokens

Pruebas con React Testing Library

Escribe pruebas que ejercitan un componente como lo hace un usuario, consultando por rol y etiqueta.

Úsalo cuando: Un componente no tiene pruebas, o sus pruebas se rompen en cada refactorización porque comprueban detalles de implementación.

prompt
You are a senior React engineer writing tests with React Testing Library and Vitest.

## Task
Write tests for the component below that cover the behaviors listed.

## Requirements
- Query elements by role, label, or text; never by class name or test id.
- Use userEvent for every interaction.
- Write one test per behavior, named as a sentence describing what the user sees.
- Mock only the network calls named in the behaviors.
- Do not test internal state or the number of renders.

## Output format
Return one TypeScript code block containing the complete test file, followed by a bulleted list of any listed behavior you could not test and why.

## Input
<component>
{{component}}
</component>

<behaviors>
{{behaviors}}
</behaviors>

Variables

{{component}}
El código fuente del componente.
{{behaviors}}
Los comportamientos que cubrir, uno por línea.

Entrada de ejemplo

component: a LoginForm with email and password fields.
behaviors: shows an error when the email is empty; disables the button while submitting.

Salida de ejemplo

```tsx
it('shows an error when the email is empty', async () => {
  render(<LoginForm />);
  await userEvent.click(screen.getByRole('button', { name: /sign in/i }));
  expect(screen.getByRole('alert')).toHaveTextContent(/email is required/i);
});
```

Ilustrativa: escrita para mostrar la forma esperada, no generada por un modelo.

Hazlo tuyo

Edita los requisitos para que se ajusten a tus estándares y revisa el resultado. El analizador de prompts vuelve a puntuarlo mientras escribes, el optimizador elimina el relleno sin perder ningún requisito y el escáner de seguridad marca secretos y datos personales antes de que lo envíes a un modelo.

Más categorías