All skills
sergiodxa avatar

/frontend-react-router-best-practices

@9da9532

React Router performance and architecture patterns. Use when writing loaders, actions, forms, routes, or working with React Router data fetching. Triggers on tasks involving React Router routes, data loading, form handling, or route organization.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-react-router-best-practices

This session only. Nothing lands on disk.

rulesroute-component-naming.md

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

Route Component Naming

Name the default export Component in React Router route files.

Why

  • Consistent naming across all routes
  • Easy to identify as route component vs regular component
  • Matches React Router documentation conventions
  • Clear distinction from named exports (loader, action)

Pattern

// app/routes/_.users/route.tsx
import { data } from "react-router";
import { useLoaderData } from "react-router";

export async function loader({ request }: Route.LoaderArgs) {
  // ...
  return data({ users });
}

export async function action({ request }: Route.ActionArgs) {
  // ...
}

// Always name the default export "Component"
export default function Component() {
  let { users } = useLoaderData<typeof loader>();

  return (
    <div>
      <h1>Users</h1>
      <UserList users={users} />
    </div>
  );
}

Don't Use Route-Specific Names

// Bad: route-specific name
export default function UsersPage() {
  // ...
}

// Bad: generic name
export default function Page() {
  // ...
}

// Bad: index name
export default function Index() {
  // ...
}

// Good: always "Component"
export default function Component() {
  // ...
}

With ErrorBoundary

// app/routes/_.users/route.tsx
export async function loader() {
  // ...
}

export default function Component() {
  // Main route component
}

// ErrorBoundary is a named export, not default
export function ErrorBoundary() {
  let error = useRouteError();
  // ...
}

Why "Component"?

  1. React Router convention - Matches the React Router docs
  2. Searchable - Easy to find all route components
  3. Refactor-safe - Renaming route folder doesn't require renaming function
  4. Clear purpose - Instantly identifies the route's UI export

Source: SKILL.md on GitHub

2 warnings16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive set of developer guidelines and best practices for building React Router applications. It emphasizes performance, type safety, and security measures like input validation (Zod), safe redirects, and CSRF protection (Sec-Fetch). No malicious code, obfuscation, or data exfiltration patterns were detected.

  • Socket16d

    1 alert: gptSecurity

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    56/56 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

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

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-react-router-best-practices