--- 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. license: MIT metadata: author: AsyrafHussin version: "1.1.0" laravelVersion: "13.x" phpVersion: "8.3+" --- # Laravel + Inertia.js + React Comprehensive patterns for building modern monolithic applications with Laravel, Inertia.js, and React. Contains 27 rules across 5 categories, written for Inertia v3. ## 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 | Rules | |----------|----------|--------|--------|-------| | 1 | Page Components | CRITICAL | `page-` | 7 | | 2 | Forms & Validation | CRITICAL | `form-` | 9 | | 3 | Navigation | HIGH | `nav-` | 6 | | 4 | Shared Data | HIGH | `shared-` | 4 | | 5 | Layouts | MEDIUM | `layout-` | 1 | ## Quick Reference ### 1. Page Components (CRITICAL) - `page-component-structure` - Standard page component pattern - `page-props-typing` - Type page props from Laravel - `page-head-management` - Title and meta tags with Head - `page-default-layout` - Assign layouts to pages - `page-scroll-preservation` - Keep scroll position across visits - `page-partial-reloads` - Reload only the props that changed, `usePoll` - `page-deferred-props` - `Inertia::defer()` with `` ### 2. Forms & Validation (CRITICAL) - `form-useform-basic` - Basic useForm usage - `form-useform-hook` - useForm methods and state - `form-component` - `
` component for simple forms - `form-validation-errors` - Display Laravel validation errors - `form-file-uploads` - File uploads with useForm - `form-progress-indicator` - Upload and submit progress - `form-transform-data` - Transform data before submit - `form-reset-handling` - Reset fields and errors - `form-dirty-tracking` - Track and warn on unsaved changes ### 3. Navigation (HIGH) - `nav-link-component` - Use Link for navigation - `nav-programmatic` - Navigate with the router - `nav-external-links` - External links and downloads - `nav-preserve-state` - Preserve scroll and state - `nav-replace-history` - Replace vs push history - `nav-usehttp-requests` - `useHttp` for JSON requests that are not page visits ### 4. Shared Data (HIGH) - `shared-auth-user` - Access authenticated user - `shared-flash-messages` - Handle flash messages - `shared-ziggy-routes` - Named routes in JavaScript (Ziggy, or Wayfinder in starter-kit apps) - `shared-app-config` - App configuration and feature flags ### 5. Layouts (MEDIUM) - `layout-persistent` - Persistent, nested and default layouts, layout props ## Inertia v3 Notes Check these when a project moves from Inertia v2 to v3 (see the [v3 upgrade guide](https://inertiajs.com/docs/v3/getting-started/upgrade-guide)): - Requires PHP 8.2+, Laravel 11+ and React 19. - Axios is no longer shipped or required; Inertia has its own HTTP client. Use `useHttp` for non-visit requests. `qs` and `lodash-es` are no longer bundled: install them yourself if the app imports them. - `Inertia::lazy()` and `LazyProp` are removed: use `Inertia::optional()`. - `router.cancel()` is now `router.cancelAll()`. - The `invalid` event is now `httpException` and `exception` is now `networkError`. - `hideProgress()` / `revealProgress()` are removed: use `progress.hide()` / `progress.reveal()` from `@inertiajs/react`. - The `inertia` attribute on head elements is now `data-inertia`. - The initial page data is always in a `