CtrlK
BlogDocsLog inGet started
Tessl Logo
SkillPublic

dev-create-hook

Use when adding server state management to a module - creates React Query hook with caching and error handling.

Quality

76%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

Fix and improve this skill with Tessl

tessl review fix ./packs/nextjs/skills/dev-create-hook/SKILL.md
SKILL.md
Quality
Evals
Security

Create a custom hook following docs/ARCHITECTURE.md section 4.4.

Hook: $ARGUMENTS

Steps

  1. Read docs/ARCHITECTURE.md section 4.4.

  2. Determine the type:

    • Query (data reading) -> useQuery + service + adapter
    • Mutation (write/delete) -> useMutation + query invalidation
    • Pure logic (no API) -> useState + useEffect + cleanup
  3. Create the hook in hooks/use[Name].ts:

Query Hook

'use client'

import { useQuery, keepPreviousData } from '@tanstack/react-query'
import { xxxService } from '../services/xxx-service'
import { xxxAdapter } from '../adapters/xxx-adapter'

interface UseXxxListOptions {
  page: number
  pageSize?: number
  search?: string
}

export function useXxxList(options: UseXxxListOptions) {
  const { page, pageSize = 20, search = '' } = options

  const query = useQuery({
    queryKey: ['xxx', 'list', { page, pageSize, search }],
    queryFn: async () => {
      const response = await xxxService.list({ page, pageSize, search })
      return xxxAdapter.toXxxList(response.data)
    },
    staleTime: 5 * 60 * 1000,
    placeholderData: keepPreviousData,
  })

  return {
    items: query.data?.items ?? [],
    totalPages: query.data?.totalPages ?? 0,
    isLoading: query.isLoading,
    isFetching: query.isFetching,
    isEmpty: !query.isLoading && (query.data?.items.length ?? 0) === 0,
    error: query.error,
    refetch: query.refetch,
  }
}

Mutation Hook

'use client'

import { useMutation, useQueryClient } from '@tanstack/react-query'
import { xxxService } from '../services/xxx-service'
import { xxxAdapter } from '../adapters/xxx-adapter'

export function useDeleteXxx() {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: (id: string) => xxxService.delete(id),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['xxx'] })
    },
  })
}
  1. Rules:

    • Required use prefix
    • 'use client' directive (hooks are client-only)
    • Explicit staleTime for queries
    • Connect layers: service -> adapter -> React Query
    • Return typed values
  2. Validate: npx tsc --noEmit

Repository

fernandezbaptiste/specialist-agent

Path

packs/nextjs/skills/dev-create-hook/SKILL.md

Last updated
First committed

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.