# Hook Library Reference ## Overview The CodeForge hook library provides a comprehensive set of reusable hooks for managing application state, UI interactions, and business logic. All hooks follow React best practices and are fully typed with TypeScript. ## Table of Contents 1. [Data Management Hooks](#data-management-hooks) 2. [Core Utility Hooks](#core-utility-hooks) 3. [UI State Hooks](#ui-state-hooks) 4. [Form Hooks](#form-hooks) 5. [Canvas Hooks](#canvas-hooks) 6. [AI Hooks](#ai-hooks) 7. [Orchestration Hooks](#orchestration-hooks) ## Data Management Hooks ### useFiles Manage project files with full CRUD operations. ```typescript import { useFiles } from '@/hooks/data/use-files' function MyComponent() { const { files, // ProjectFile[] addFile, // (file: ProjectFile) => void updateFile, // (id: string, updates: Partial) => void deleteFile, // (id: string) => void getFile, // (id: string) => ProjectFile | undefined updateFileContent // (id: string, content: string) => void } = useFiles() // Usage addFile({ id: 'new-file', name: 'App.tsx', path: '/src/App.tsx', content: 'export default function App() {}', language: 'typescript' }) } ``` ### useModels Manage Prisma models. ```typescript import { useModels } from '@/hooks/data/use-models' function ModelDesigner() { const { models, // PrismaModel[] addModel, // (model: PrismaModel) => void updateModel, // (id: string, updates: Partial) => void deleteModel, // (id: string) => void getModel // (id: string) => PrismaModel | undefined } = useModels() // Add a new model addModel({ id: 'user-model', name: 'User', fields: [ { name: 'id', type: 'String', isId: true }, { name: 'email', type: 'String', isUnique: true } ], relations: [] }) } ``` ### useComponents Manage React components. ```typescript import { useComponents } from '@/hooks/data/use-components' function ComponentBuilder() { const { components, // ComponentNode[] addComponent, // (component: ComponentNode) => void updateComponent, // (id: string, updates: Partial) => void deleteComponent, // (id: string) => void getComponent // (id: string) => ComponentNode | undefined } = useComponents() } ``` ### useWorkflows Manage n8n-style workflows. ```typescript import { useWorkflows } from '@/hooks/data/use-workflows' function WorkflowDesigner() { const { workflows, // Workflow[] addWorkflow, // (workflow: Workflow) => void updateWorkflow, // (id: string, updates: Partial) => void deleteWorkflow, // (id: string) => void getWorkflow // (id: string) => Workflow | undefined } = useWorkflows() } ``` ### useLambdas Manage serverless functions. ```typescript import { useLambdas } from '@/hooks/data/use-lambdas' function LambdaDesigner() { const { lambdas, // Lambda[] addLambda, // (lambda: Lambda) => void updateLambda, // (id: string, updates: Partial) => void deleteLambda, // (id: string) => void getLambda // (id: string) => Lambda | undefined } = useLambdas() } ``` ## Core Utility Hooks ### useKVState Enhanced KV storage with validation and transformations. ```typescript import { useKVState } from '@/hooks/core/use-kv-state' function MyComponent() { const [value, setValue] = useKVState({ key: 'my-data', defaultValue: { count: 0 }, validate: (data) => data.count >= 0, transform: (data) => ({ ...data, lastUpdated: Date.now() }) }) } ``` ### useClipboard Copy to clipboard with feedback. ```typescript import { useClipboard } from '@/hooks/core/use-clipboard' function CopyButton({ text }: { text: string }) { const { copy, copied } = useClipboard() return ( ) } ``` ### useDebouncedSave Auto-save with debouncing. ```typescript import { useDebouncedSave } from '@/hooks/core/use-debounced-save' function Editor() { const [content, setContent] = useState('') useDebouncedSave(content, async (value) => { await saveToServer(value) }, 1000) // 1 second delay return