Prompt library

React prompts

Prompts for React components: finding wasted renders, splitting large components, and writing tests that follow user behavior.

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

React re-render audit

Finds the causes of unnecessary re-renders in a component and gives the smallest fix for each.

Use it when: A component feels slow or the profiler shows it rendering on every keystroke.

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}}
The component source, with the children it renders if you have them.

Example input

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

Example output

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.

Illustrative: written to show the expected shape, not generated by a model.

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

React Testing Library tests

Writes tests that exercise a component the way a user does, querying by role and label.

Use it when: A component has no tests, or its tests break on every refactor because they check implementation details.

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}}
The component source.
{{behaviors}}
The behaviors to cover, one per line.

Example input

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

Example output

```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);
});
```

Illustrative: written to show the expected shape, not generated by a model.

Make it yours

Edit the requirements to match your standards, then check the result. Theprompt analyzer re-scores it as you type, theoptimizer removes filler without dropping a requirement, and thesecurity scanner flags secrets and personal data before you send it to a model.

More categories