A Next.js application that automatically generates TypeScript-powered React hooks for API calls. This tool helps React developers quickly create production-ready custom hooks with proper typing, error handling, and optional features like caching and retry logic.
- π Automatic Hook Generation - Generate complete React hooks from API responses
- π TypeScript Support - Full TypeScript interfaces generated from JSON responses
- π― Path Parameter Detection - Automatically detects and handles path parameters like
{id},{userId} - β‘ Optional Features - Toggle caching, retry logic, and request cancellation
- π One-Click Copy - Copy generated code to clipboard instantly
- π¨ Clean UI - Modern, minimalist design with smooth animations
- π± Responsive - Works seamlessly on desktop and mobile devices
- Next.js 14+ with App Router
- TypeScript (strict mode)
- Tailwind CSS for styling
- React hooks for state management
- Native
fetchAPI (no external libraries)
- Node.js 18+ installed
- npm or yarn package manager
- Clone or download this repository
- Install dependencies:
npm install- Start the development server:
npm run dev- Open http://localhost:3000 in your browser
- API Endpoint URL - Enter your API endpoint (e.g.,
https://api.example.com/users/{id})- Use curly braces
{}for path parameters
- Use curly braces
- Select HTTP Method - Choose GET or POST
- Configure Options - Toggle optional features:
- Caching - Cache responses for 5 minutes
- Retry Logic - Retry failed requests up to 3 times
- Request Cancellation - Cancel pending requests on component unmount (GET only)
Choose one of two methods:
- Fetch from API - Automatically fetch a sample response from the endpoint
- Paste JSON Response - Manually paste a JSON response
The tool generates three code sections:
- Hook Code - Complete React hook implementation
- Types - TypeScript interfaces for your data
- Usage Example - Example component showing how to use the hook
Click the "Copy" button on any tab to copy the code to your clipboard.
- URL:
https://jsonplaceholder.typicode.com/users/1 - Method: GET
- Options: Retry enabled
import { useState, useEffect, useCallback } from 'react';
export function useUser(userId: string) {
const [data, setData] = useState<User | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const fetchUser = useCallback(async () => {
setLoading(true);
setError(null);
let lastError: Error | null = null;
for (let attempt = 0; attempt < 3; attempt++) {
try {
const response = await fetch(`https://jsonplaceholder.typicode.com/users/${userId}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = await response.json();
setData(result);
break;
} catch (err) {
lastError = err instanceof Error ? err : new Error('Unknown error');
if (attempt === 2) {
setError(lastError.message);
}
}
}
setLoading(false);
}, [userId]);
useEffect(() => {
fetchUser();
}, [fetchUser]);
return { data, loading, error, refetch: fetchUser };
}src/
βββ app/
β βββ layout.tsx # Root layout with metadata
β βββ page.tsx # Main page component
β βββ globals.css # Global styles
βββ components/
β βββ Header.tsx # App header
β βββ ApiInputForm.tsx # Main input form
β βββ JsonInputModal.tsx # Modal for pasting JSON
β βββ CodeDisplay.tsx # Code display with tabs
β βββ CopyButton.tsx # Copy to clipboard button
βββ lib/
β βββ codeGenerator.ts # Main code generation logic
β βββ typeGenerator.ts # TypeScript interface generation
β βββ urlParser.ts # URL parsing and hook naming
β βββ utils.ts # Helper utilities
βββ types/
βββ index.ts # TypeScript type definitions
GET /users/{id}βuseUserGET /usersβuseUsersPOST /usersβuseCreateUser
- Analyzes JSON structure
- Handles nested objects
- Handles arrays (
Type[]) - Infers primitive types (string, number, boolean, null)
- For POST: generates separate
CreateXInputinterface
- Detected from curly braces:
{id},{userId},{postId} - Automatically added as function parameters
- Type-safe with TypeScript
npm run build
npm startThis is an MVP (Minimum Viable Product). Future enhancements could include:
- Support for more HTTP methods (PUT, PATCH, DELETE)
- Authentication handling
- Request/response interceptors
- More customization options
- Export to different formats
- Dark mode support
MIT License - feel free to use this project for any purpose.
For issues or questions, please open an issue on the GitHub repository.
Built with β€οΈ using Next.js and TypeScript