Use when adding server state management to a module - creates React Query hook with caching and error handling.
76%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./packs/react/skills/dev-create-hook/SKILL.mdCreate a custom hook following docs/ARCHITECTURE.md section 4.4.
Hook: $ARGUMENTS
Read docs/ARCHITECTURE.md section 4.4.
Determine the type:
useQuery + service + adapteruseMutation + query invalidationCreate the hook in hooks/use[Name].ts:
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 }
}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'] })
},
})
}Required: use prefix, staleTime for queries, queryKey as array, adapter in queryFn.
Connect the layers: service -> adapter -> React Query
Validate: npx tsc --noEmit
fernandezbaptiste/specialist-agent
cd716d9
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.