Prompt Details
Model
(claude-4-7-opus)
Token size
240
Example input
[hook_type]: useAuth
[framework]: Next.js 14
[chain_steps]: validate, call_api, persist_token, check_expiry, refresh_token
[memory_state]: token, user, expires_at
Example output
import { useState, useEffect, useCallback } from 'react';
interface User {
id: string;
email: string;
name: string;
}
interface AuthState {
token: string | null;
user: User | null;
expires_at: number | null;
isLoading: boolean;
error: string | null;
}
const useAuth = () => {
const [state, setState] = useState<AuthState>({
token: null,
user: null,
expires_at: null,
isLoading: false,
error: null,
});
const login = useCallback(async (email: string, password: string) => {
setState(prev => ({ ...prev, isLoading: true, error: null }));
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
if (!response.ok) throw new Error('Invalid credentials');
const { token, user, expiresIn } = await response.json();
setState({
token,
user,
expires_at: Date.now() + expiresIn * 1000,
isLoading: false,
error: null,
});
} catch (error) {
setState(prev => ({
...prev,
isLoading: false,
error: (error as Error).message,
}));
}
}, []);
const logout = useCallback(() => {
setState({ token: null, user: null, expires_at: null, isLoading: false, error: null });
}, []);
return { ...state, login, logout, isAuthenticated: !!state.token };
};
export default useAuth;
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-7-OPUS
Production-grade React hook generator engineered for Claude's tool_use API. Generates any custom hook — authentication, data fetching, form handling, local storage, WebSocket, debounce, infinite scroll, and more. Structured JSON schema with chain-of-thought execution. Full TypeScript, proper error states, loading states, and zero placeholders. 95%+ parseable output every time. Not a chat prompt — an engineered tool_use schema blueprint.
...more
Added 1 week ago
