All skills
asyrafhussin avatar

/laravel-inertia-react

@ac26821

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.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/laravel-inertia-react

This session only. Nothing lands on disk.

rulespage-default-layout.md

≈678 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Page Default Layout

Assign layouts to pages using the static layout property pattern to enable persistent layouts and avoid unnecessary re-renders.

Bad Example

// Anti-pattern: Wrapping layout inside the component
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';

export default function Dashboard({ auth }) {
  return (
    <AuthenticatedLayout user={auth.user}>
      <div className="py-12">
        <h1>Dashboard</h1>
      </div>
    </AuthenticatedLayout>
  );
}

// Anti-pattern: Using a wrapper component
function DashboardWithLayout(props) {
  return (
    <AuthenticatedLayout>
      <Dashboard {...props} />
    </AuthenticatedLayout>
  );
}

export default DashboardWithLayout;

Good Example

// resources/js/Pages/Dashboard.tsx
import { Head } from '@inertiajs/react';
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import { PageProps } from '@/types';

export default function Dashboard({ auth }: PageProps) {
  return (
    <>
      <Head title="Dashboard" />
      <div className="py-12">
        <div className="mx-auto max-w-7xl sm:px-6 lg:px-8">
          <h1>Welcome, {auth.user.name}</h1>
        </div>
      </div>
    </>
  );
}

Dashboard.layout = (page: React.ReactNode) => (
  <AuthenticatedLayout children={page} />
);

// For TypeScript, extend the function type
// resources/js/types/index.d.ts
import { ReactNode } from 'react';

declare module '@inertiajs/react' {
  interface PageComponent<P = {}> {
    (props: P): ReactNode;
    layout?: (page: ReactNode) => ReactNode;
  }
}

// Alternative: Typed page component
import { PageComponent } from '@/types';

const Dashboard: PageComponent<PageProps> = ({ auth }) => {
  return (
    <>
      <Head title="Dashboard" />
      <div>Dashboard content</div>
    </>
  );
};

Dashboard.layout = (page) => <AuthenticatedLayout children={page} />;

export default Dashboard;

Why

Using the static layout property pattern is important because:

  1. Persistent Layouts: Layouts remain mounted between page visits, preserving their state
  2. Performance: Audio players, video, scroll position, and form state persist across navigation
  3. Fewer Re-renders: The layout doesn't unmount/remount on every page change
  4. Cleaner Components: Page components focus on their content, not layout wrapping
  5. Consistency: All pages follow the same pattern, making the codebase predictable
  6. Flexibility: Easy to switch layouts or use conditional layouts per page

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a comprehensive set of best practices and patterns for building applications with Laravel, Inertia.js, and React. The content consists of architectural guidance and code examples that follow official framework standards and do not exhibit any malicious behavior or security risks.

  • Socket16d

    1 alert: gptAnomaly

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    30 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at ac26821. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
Other metadata
metadata
{
  "author": "AsyrafHussin",
  "version": "1.0.2",
  "laravelVersion": "13.x",
  "phpVersion": "8.3+"
}

README badge

README badge for asyrafhussin/agent-skills/laravel-inertia-react