--- name: inertia-react-development description: >- Develops Inertia.js v2 React client-side applications. Activates when creating React pages, forms, or navigation; using ,
, useForm, or router; working with deferred props, prefetching, or polling; or when user mentions React with Inertia, React pages, React forms, or React navigation. --- @php /** @var \Laravel\Boost\Install\GuidelineAssist $assist */ @endphp # Inertia React Development ## When to Apply Activate this skill when: - Creating or modifying React page components for Inertia - Working with forms in React (using `` or `useForm`) - Implementing client-side navigation with `` or `router` - Using v2 features: deferred props, prefetching, or polling - Building React-specific features with the Inertia protocol ## Documentation Use `search-docs` for detailed Inertia v2 React patterns and documentation. ## Basic Usage ### Page Components Location React page components should be placed in the `resources/js/Pages` directory. ### Page Component Structure @boostsnippet("Basic React Page Component", "react") export default function UsersIndex({ users }) { return (

Users

) } @endboostsnippet ## Client-Side Navigation ### Basic Link Component Use `` for client-side navigation instead of traditional `` tags: @boostsnippet("Inertia React Navigation", "react") import { Link, router } from '@inertiajs/react' Home Users View User @endboostsnippet ### Link with Method @boostsnippet("Link with POST Method", "react") import { Link } from '@inertiajs/react' Logout @endboostsnippet ### Prefetching Prefetch pages to improve perceived performance: @boostsnippet("Prefetch on Hover", "react") import { Link } from '@inertiajs/react' Users @endboostsnippet ### Programmatic Navigation @boostsnippet("Router Visit", "react") import { router } from '@inertiajs/react' function handleClick() { router.visit('/users') } // Or with options router.visit('/users', { method: 'post', data: { name: 'John' }, onSuccess: () => console.log('Success!'), }) @endboostsnippet ## Form Handling @if($assist->inertia()->hasFormComponent()) ### Form Component (Recommended) The recommended way to build forms is with the `` component: @boostsnippet("Form Component Example", "react") import { Form } from '@inertiajs/react' export default function CreateUser() { return ( {({ errors, processing, wasSuccessful }) => ( <> {errors.name &&
{errors.name}
} {errors.email &&
{errors.email}
} {wasSuccessful &&
User created!
} )} ) } @endboostsnippet ### Form Component With All Props @boostsnippet("Form Component Full Example", "react") import { Form } from '@inertiajs/react'
{({ errors, hasErrors, processing, progress, wasSuccessful, recentlySuccessful, clearErrors, resetAndClearErrors, defaults, isDirty, reset, submit }) => ( <> {errors.name &&
{errors.name}
} {progress && ( {progress.percentage}% )} {wasSuccessful &&
Saved!
} )}
@endboostsnippet @if($assist->inertia()->hasFormComponentResets()) ### Form Component Reset Props The `
` component supports automatic resetting: - `resetOnError` - Reset form data when the request fails - `resetOnSuccess` - Reset form data when the request succeeds - `setDefaultsOnSuccess` - Update default values on success Use the `search-docs` tool with a query of `form component resetting` for detailed guidance. @boostsnippet("Form with Reset Props", "react") import { Form } from '@inertiajs/react' {({ errors, processing, wasSuccessful }) => ( <> {errors.name &&
{errors.name}
} )}
@endboostsnippet @else Note: This version of Inertia does not support `resetOnError`, `resetOnSuccess`, or `setDefaultsOnSuccess` on the `
` component. Using these props will cause errors. Upgrade to Inertia v2.2.0+ to use these features. @endif Forms can also be built using the `useForm` helper for more programmatic control. Use the `search-docs` tool with a query of `useForm helper` for guidance. @endif ### `useForm` Hook @if($assist->inertia()->hasFormComponent() === false) For Inertia v2.0.x: Build forms using the `useForm` helper as the `` component is not available until v2.1.0+. @else For more programmatic control or to follow existing conventions, use the `useForm` hook: @endif @boostsnippet("useForm Hook Example", "react") import { useForm } from '@inertiajs/react' export default function CreateUser() { const { data, setData, post, processing, errors, reset } = useForm({ name: '', email: '', password: '', }) function submit(e) { e.preventDefault() post('/users', { onSuccess: () => reset('password'), }) } return ( setData('name', e.target.value)} /> {errors.name &&
{errors.name}
} setData('email', e.target.value)} /> {errors.email &&
{errors.email}
} setData('password', e.target.value)} /> {errors.password &&
{errors.password}
}
) } @endboostsnippet ## Inertia v2 Features ### Deferred Props Use deferred props to load data after initial page render: @boostsnippet("Deferred Props with Empty State", "react") export default function UsersIndex({ users }) { // users will be undefined initially, then populated return (

Users

{!users ? (
) : (
    {users.map(user => (
  • {user.name}
  • ))}
)}
) } @endboostsnippet ### Polling Automatically refresh data at intervals: @boostsnippet("Polling Example", "react") import { router } from '@inertiajs/react' import { useEffect } from 'react' export default function Dashboard({ stats }) { useEffect(() => { const interval = setInterval(() => { router.reload({ only: ['stats'] }) }, 5000) // Poll every 5 seconds return () => clearInterval(interval) }, []) return (

Dashboard

Active Users: {stats.activeUsers}
) } @endboostsnippet ### WhenVisible (Infinite Scroll) Load more data when user scrolls to a specific element: @boostsnippet("Infinite Scroll with WhenVisible", "react") import { WhenVisible } from '@inertiajs/react' export default function UsersList({ users }) { return (
{users.data.map(user => (
{user.name}
))} {users.next_page_url && ( Loading more...
} /> )} ) } @endboostsnippet ## Common Pitfalls - Using traditional `
` links instead of Inertia's `` component (breaks SPA behavior) - Forgetting to add loading states (skeleton screens) when using deferred props - Not handling the `undefined` state of deferred props before data loads - Using `
` without preventing default submission (use `` component or `e.preventDefault()`) - Forgetting to check if `` component is available in your Inertia version