--- name: laravel-inertia-react description: Laravel + Inertia.js + React integration patterns. Use when building Inertia page components, handling forms with useForm, managing shared data, or implementing persistent layouts. Triggers on tasks involving Inertia.js, page props, form handling, or Laravel React integration. --- # Laravel + Inertia.js + React Comprehensive patterns for building modern monolithic applications with Laravel, Inertia.js, and React. Contains 30+ rules for seamless full-stack development. ## When to Apply Reference these guidelines when: - Creating Inertia page components - Handling forms with useForm hook - Managing shared data and authentication - Implementing persistent layouts - Navigating between pages ## Rule Categories by Priority | Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | Page Components | CRITICAL | `page-` | | 2 | Forms & Validation | CRITICAL | `form-` | | 3 | Navigation & Links | HIGH | `nav-` | | 4 | Shared Data | HIGH | `shared-` | | 5 | Layouts | MEDIUM | `layout-` | | 6 | File Uploads | MEDIUM | `upload-` | | 7 | Advanced Patterns | LOW | `advanced-` | ## Quick Reference ### 1. Page Components (CRITICAL) - `page-props-typing` - Type page props from Laravel - `page-component-structure` - Standard page component pattern - `page-head-management` - Title and meta tags with Head - `page-default-layout` - Assign layouts to pages ### 2. Forms & Validation (CRITICAL) - `form-useform-basic` - Basic useForm usage - `form-validation-errors` - Display Laravel validation errors - `form-processing-state` - Handle form submission state - `form-reset-preserve` - Reset vs preserve form data - `form-nested-data` - Handle nested form data - `form-transform` - Transform data before submit ### 3. Navigation & Links (HIGH) - `nav-link-component` - Use Link for navigation - `nav-preserve-state` - Preserve scroll and state - `nav-partial-reloads` - Reload only what changed - `nav-replace-history` - Replace vs push history ### 4. Shared Data (HIGH) - `shared-auth-user` - Access authenticated user - `shared-flash-messages` - Handle flash messages - `shared-global-props` - Access global props - `shared-typescript` - Type shared data ### 5. Layouts (MEDIUM) - `layout-persistent` - Persistent layouts pattern - `layout-nested` - Nested layouts - `layout-default` - Default layout assignment - `layout-conditional` - Conditional layouts ### 6. File Uploads (MEDIUM) - `upload-basic` - Basic file upload - `upload-progress` - Upload progress tracking - `upload-multiple` - Multiple file uploads ### 7. Advanced Patterns (LOW) - `advanced-polling` - Real-time polling - `advanced-prefetch` - Prefetch pages - `advanced-modal-pages` - Modal as pages - `advanced-infinite-scroll` - Infinite scrolling ## Essential Patterns ### Page Component with TypeScript ```tsx // resources/js/Pages/Posts/Index.tsx import { Head, Link } from '@inertiajs/react' interface Post { id: number title: string excerpt: string created_at: string author: { id: number name: string } } interface Props { posts: { data: Post[] links: { url: string | null; label: string; active: boolean }[] } filters: { search?: string } } export default function Index({ posts, filters }: Props) { return ( <>

Posts

{posts.data.map((post) => (

{post.title}

{post.excerpt}

By {post.author.name}

))}
) } ``` ### Form with useForm ```tsx // resources/js/Pages/Posts/Create.tsx import { Head, useForm, Link } from '@inertiajs/react' import { FormEvent } from 'react' interface Category { id: number name: string } interface Props { categories: Category[] } export default function Create({ categories }: Props) { const { data, setData, post, processing, errors, reset } = useForm({ title: '', body: '', category_id: '', }) const handleSubmit = (e: FormEvent) => { e.preventDefault() post(route('posts.store'), { onSuccess: () => reset(), }) } return ( <>
setData('title', e.target.value)} className="w-full border rounded px-3 py-2" /> {errors.title && (

{errors.title}

)}
{errors.category_id && (

{errors.category_id}

)}