All skills
asyrafhussin avatar

/state-management

@10bb16e

React Query and Zustand patterns for state management. Use when implementing data fetching, caching, mutations, or client-side state. Triggers on tasks involving useQuery, useMutation, Zustand stores, caching, or state management.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/state-management

This session only. Nothing lands on disk.

rules_template.md

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

Rule Title Here

Impact: MEDIUM (optional impact description)

Brief explanation of the rule and why it matters. Focus on the problem it solves and the value it provides for state management.

Bad Example

// Anti-pattern: Description of what's wrong
const { data } = useQuery({
  queryKey: ['data'],
  queryFn: fetchData,
  // Issues: explains the problems
})

// Another bad pattern example
const mutation = useMutation({
  mutationFn: updateData,
  // Missing important configuration
})

Good Example

// Correct pattern: Description of what's right
const { data } = useQuery({
  queryKey: queryKeys.data.list(filters),
  queryFn: () => fetchData(filters),
  staleTime: 5 * 60 * 1000,
  gcTime: 30 * 60 * 1000,
})

// Another good pattern example
const mutation = useMutation({
  mutationFn: updateData,
  onSuccess: () => {
    queryClient.invalidateQueries({ queryKey: ['data'] })
  },
  onError: (error) => {
    console.error('Update failed:', error)
  },
})

// With custom hook for reusability
export function useDataQuery(filters?: DataFilters) {
  return useQuery({
    queryKey: queryKeys.data.list(filters ?? {}),
    queryFn: () => fetchData(filters),
    staleTime: 5 * 60 * 1000,
  })
}

// Zustand store example
interface DataStore {
  items: Data[]
  addItem: (item: Data) => void
  removeItem: (id: string) => void
}

export const useDataStore = create<DataStore>((set) => ({
  items: [],
  addItem: (item) => set((state) => ({ items: [...state.items, item] })),
  removeItem: (id) => set((state) => ({
    items: state.items.filter((i) => i.id !== id)
  })),
}))

Why

  1. Performance: Explain the performance benefits with specific metrics or scenarios.

  2. User Experience: Describe how this improves the user's experience.

  3. Maintainability: Explain how this makes code easier to maintain and understand.

  4. Type Safety: If applicable, describe TypeScript benefits.

  5. Consistency: Explain how this promotes consistent patterns across the codebase.

  6. Error Handling: Describe how this improves error handling and recovery.

When to use this pattern:

  • Specific scenario 1
  • Specific scenario 2
  • Specific scenario 3

When NOT to use:

  • Anti-scenario 1
  • Anti-scenario 2

Reference: Link to relevant documentation

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides secure and comprehensive documentation for managing application state using React Query and Zustand. It includes critical security warnings against storing sensitive data in local storage and promotes best practices for data fetching, caching, and error handling. No malicious patterns or security vulnerabilities were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    32 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 10bb16e. 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
metadata
{
  "author": "agent-skills",
  "version": "1.1.0"
}

README badge

README badge for asyrafhussin/agent-skills/state-management