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-props-typing.md

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

Page Props Typing

All Inertia page props should be strongly typed using TypeScript interfaces that extend a base PageProps type containing shared data.

Bad Example

// Anti-pattern: Using any or missing types
export default function Users({ users, filters }: any) {
  return (
    <div>
      {users.map((user) => (
        <div key={user.id}>{user.name}</div>
      ))}
    </div>
  );
}

// Anti-pattern: Inline typing without extending base props
export default function Users({
  users
}: {
  users: { id: number; name: string }[]
}) {
  // Missing auth, flash, and other shared props
}

Good Example

// resources/js/types/index.d.ts
export interface User {
  id: number;
  name: string;
  email: string;
  email_verified_at: string | null;
  created_at: string;
  updated_at: string;
}

export interface PaginatedData<T> {
  data: T[];
  links: {
    first: string;
    last: string;
    prev: string | null;
    next: string | null;
  };
  meta: {
    current_page: number;
    from: number;
    last_page: number;
    path: string;
    per_page: number;
    to: number;
    total: number;
  };
}

export interface PageProps {
  auth: {
    user: User;
  };
  flash: {
    success?: string;
    error?: string;
  };
  ziggy: {
    url: string;
    port: number | null;
    defaults: Record<string, unknown>;
    routes: Record<string, unknown>;
  };
}

// resources/js/Pages/Users/Index.tsx
import { PageProps, PaginatedData, User } from '@/types';

interface Filters {
  search: string;
  role: string;
  status: 'active' | 'inactive' | 'all';
}

interface UsersIndexProps extends PageProps {
  users: PaginatedData<User>;
  filters: Filters;
  roles: { value: string; label: string }[];
}

export default function Index({ auth, users, filters, roles }: UsersIndexProps) {
  return (
    <div>
      <h1>Users ({users.meta.total})</h1>
      {users.data.map((user) => (
        <UserCard key={user.id} user={user} />
      ))}
    </div>
  );
}

Why

Proper props typing is essential for Inertia applications:

  1. Contract Enforcement: Types create a contract between Laravel controllers and React components
  2. IDE Support: Autocomplete and inline documentation improve developer productivity
  3. Error Prevention: Catch typos and missing properties before runtime
  4. Refactoring Safety: TypeScript will flag all affected components when data shapes change
  5. Documentation: Types serve as living documentation for the data flow
  6. Shared Data Access: Extending PageProps ensures access to auth, flash messages, and Ziggy routes

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