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/react/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 + useMemo + useEffect
  3. Create the hook in hooks/use[Name].ts:

Query Hook Template

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

interface UseXxxOptions {
  page: number
  pageSize?: number
}

export function useXxx(options: UseXxxOptions) {
  const { page, pageSize = 20 } = options

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

  return { data, isLoading, isFetching, error, refetch }
}

Mutation Hook Template

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

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

  return useMutation({
    mutationFn: async (input: CreateXxxInput) => {
      const payload = xxxAdapter.toCreatePayload(input)
      const response = await xxxService.create(payload)
      return xxxAdapter.toXxx(response.data)
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['xxx'] })
    },
  })
}
  1. Required: use prefix, staleTime for queries, queryKey as array, adapter in queryFn.

  2. Connect the layers: service -> adapter -> React Query

  3. Validate: npx tsc --noEmit

Repository

fernandezbaptiste/specialist-agent

Path

packs/react/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.