Biblioteca de prompts

Prompts de React

Prompts para componentes React: encontrar renderizações desnecessárias, dividir componentes grandes e escrever testes que seguem o comportamento do usuário.

Os prompts estão em inglês, o idioma em que foram escritos e testados. As descrições e instruções destas páginas estão traduzidas.

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

Auditoria de re-renderizações no React

Encontra as causas de re-renderizações desnecessárias em um componente e dá a menor correção para cada uma.

Use quando: Um componente parece lento ou o profiler mostra que ele renderiza a cada tecla digitada.

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>

Variáveis

{{component}}
O código-fonte do componente, com os filhos que ele renderiza, se você os tiver.

Entrada de exemplo

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

Saída de exemplo

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 a forma esperada, não gerada por um modelo.

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

Testes com React Testing Library

Escreve testes que exercitam um componente como um usuário faz, consultando por papel e rótulo.

Use quando: Um componente não tem testes, ou seus testes quebram a cada refatoração porque verificam detalhes de implementação.

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>

Variáveis

{{component}}
O código-fonte do componente.
{{behaviors}}
Os comportamentos a cobrir, um por linha.

Entrada de exemplo

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

Saída de exemplo

```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 a forma esperada, não gerada por um modelo.

Deixe com a sua cara

Edite os requisitos para seguir os seus padrões e depois verifique o resultado. O analisador de prompts o pontua de novo enquanto você digita, o otimizador remove enchimento sem perder nenhum requisito e o scanner de segurança sinaliza segredos e dados pessoais antes de você enviá-lo a um modelo.

Mais categorias