Skip to content
Back to skills

Frontend Pattern

ASecurity

Frontend development patterns — component composition, state management, URL-as-state, data fetching, and animation best practices for React/TypeScript web applications

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 9, 2026
ai-agentstypescriptgoreactcode-reviewfrontendsecurity

Works with

  • cli

Security analysis

A100/100

Scanned October 9, 2026

npx -y skills add alisattorov06/ali-kiro --skill frontend-pattern --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Frontend Pattern?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Frontend Pattern
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/alisattorov06-frontend-pattern/badge)](https://www.skillsdirectory.com/skills/alisattorov06-frontend-pattern)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: frontend-pattern
description: Frontend development patterns — component composition, state management, URL-as-state, data fetching, and animation best practices for React/TypeScript web applications
origin: FlowDeck
---

# Frontend Pattern Skill

Implements maintainable, performant frontend patterns using React and TypeScript.

## When to Activate

Activate when:
- Building new UI components
- Setting up state management
- Implementing data fetching
- Adding animations or transitions
- Structuring a new feature module

## Component Patterns

### Compound Components

Use compound components when related UI shares state and interaction semantics:

```tsx
<Tabs defaultValue="overview">
  <Tabs.List>
    <Tabs.Trigger value="overview">Overview</Tabs.Trigger>
    <Tabs.Trigger value="settings">Settings</Tabs.Trigger>
  </Tabs.List>
  <Tabs.Content value="overview">...</Tabs.Content>
  <Tabs.Content value="settings">...</Tabs.Content>
</Tabs>
```

- Parent owns state via `useState` or context
- Children consume via context — no prop drilling
- Keeps keyboard handling, ARIA, and focus logic in the headless layer

### Container / Presentational Split

```tsx
// Container — owns data loading and side effects
function UserProfileContainer({ userId }: { userId: string }) {
  const { data, isLoading } = useUser(userId);
  if (isLoading) return <Skeleton />;
  return <UserProfileView user={data} />;
}

// Presentational — receives props, renders UI
function UserProfileView({ user }: { user: User }) {
  return (
    <div>
      <Avatar src={user.avatar} />
      <h1>{user.name}</h1>
    </div>
  );
}
```

## State Management

| Concern | Tooling |
|---------|---------|
| Server state | TanStack Query, SWR, tRPC |
| Client state | Zustand, Jotai, signals |
| URL state | search params, route segments |
| Form state | React Hook Form or equivalent |

**Do not duplicate server state into client stores.** Derive values instead of storing redundant computed state.

## URL As State

Persist shareable, bookmarkable state in the URL:

```tsx
// Good: filters, sort, pagination in URL
const [searchParams, setSearchParams] = useSearchParams();
const filter = searchParams.get('filter') ?? 'all';

// Usage
<button onClick={() => setSearchParams({ filter: 'active' })}>
  Active
</button>
```

## Data Fetching Patterns

### Stale-While-Revalidate

Return cached data immediately, revalidate in background:

```tsx
const { data } = useQuery({
  queryKey: ['users', userId],
  queryFn: () => fetchUser(userId),
  staleTime: 5 * 60 * 1000, // 5 minutes
});
```

### Optimistic Updates

```tsx
const mutation = useMutation({
  mutationFn: updateUser,
  onMutate: async (newData) => {
    await queryClient.cancelQueries({ queryKey: ['user', newData.id] });
    const previous = queryClient.getQueryData(['user', newData.id]);
    queryClient.setQueryData(['user', newData.id], newData);
    return { previous };
  },
  onError: (err, newData, context) => {
    queryClient.setQueryData(['user', newData.id], context.previous);
  },
});
```

## CSS Custom Properties

Define design tokens as CSS variables — do not hardcode values:

```css
:root {
  --color-surface: oklch(98% 0 0);
  --color-text: oklch(18% 0 0);
  --color-accent: oklch(68% 0.21 250);

  --text-base: clamp(1rem, 0.92rem + 0.4vw, 1.125rem);
  --space-section: clamp(4rem, 3rem + 5vw, 10rem);

  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}
```

## Animation Guidelines

Use compositor-friendly properties only:

```
✅ transform, opacity, clip-path, filter
❌ width, height, top, left, margin, padding, border, font-size
```

```tsx
// Good
const style = { opacity: isVisible ? 1 : 0, transform: `translateY(${isVisible ? 0 : 20}px)` };

// Bad
const style = { height: isVisible ? 'auto' : 0 };
```

## Related Skills

- [code-review](code-review) — Review frontend code for quality
- [security-scan](security-scan) — Check for XSS and injection vulnerabilities
- [test-coverage](test-coverage) — Ensure UI component tests exist

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.