P
⚡ProductiviteIntermediateAll AIs

Custom React Hook

Centralize fetching logic into reusable hooks

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Create a custom React hook useData[RESOURCE_NAME] that manages API calls to the endpoint [URL_ENDPOINT]. The hook should expose: the data, a loading state (isLoading), an error state, a refetch function, and support request cancellation with AbortController. Include full TypeScript typing.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Use Cases

Centralize fetching logic into reusable hooks

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Astuce : Utilisez AbortController dans le `useEffect` pour annuler la requête si le composant est démonté avant la réponse. Pensez aussi à typer le retour du hook avec un type générique `<T>` pour réutiliser le hook avec différentes ressources.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

⚡ProductiviteIntermediateAll AIs

Punchy Introduction

Introduction Writing

341
⚡ProductiviteBeginnerAll AIs

Prompt to Write a Professional Quote Request Email

A complete prompt to generate a structured, professional and customizable quote request email adapted to your industry and recipient.

334
⚡ProductiviteBeginnerAll AIs

Convert CSS to Tailwind

Migrate from standard CSS to Tailwind CSS

343
⚡ProductiviteAdvancedAll AIs

Probability Calibration

Improve the reliability of predicted probabilities

369