Cursor rule
.cursor/rules/hooks.mdcCustom hooks patterns for data fetching, forms, and UI state management
Cursor rules
Quality
61/100
Scores the file, not the repository.Length
329 words
10 headings · 4 code blocksRepository
63
— · pushed 15 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# Custom Hooks Rules89## Hook Organization Patterns1011### Data Fetching Hooks12```tsx13// hooks/useUsers.ts14export const useUsers = () => {15 return useQuery({16 queryKey: ['users'],17 queryFn: () => userService.getAllUsers(),18 staleTime: 5 * 60 * 1000, // 5 minutes19 })20}2122export const useUser = (id: string) => {23 return useQuery({24 queryKey: ['users', id],25 queryFn: () => userService.getUser(id),26 enabled: !!id,27 })28}29```3031### Form Hooks32```tsx33// hooks/useUserForm.ts34export const useUserForm = (initialData?: Partial<User>) => {35 const form = useForm<UserFormData>({36 resolver: zodResolver(userSchema),37 defaultValues: initialData || {},38 })3940 const { mutate: saveUser, isPending } = useMutation({41 mutationFn: userService.updateUser,42 onSuccess: () => toast.success('User saved'),43 onError: (error) => toast.error(error.message),44 })4546 return { form, saveUser, isPending }47}48```4950### UI State Hooks51```tsx52// hooks/useDisclosure.ts53export const useDisclosure = (initialState = false) => {54 const [isOpen, setIsOpen] = useState(initialState)5556 const open = useCallback(() => setIsOpen(true), [])57 const close = useCallback(() => setIsOpen(false), [])58 const toggle = useCallback(() => setIsOpen(prev => !prev), [])5960 return { isOpen, open, close, toggle }61}62```6364### Local Storage Hook65```tsx66// hooks/useLocalStorage.ts67export const useLocalStorage = <T>(key: string, initialValue: T) => {68 const [storedValue, setStoredValue] = useState<T>(() => {69 try {70 const item = window.localStorage.getItem(key)71 return item ? JSON.parse(item) : initialValue72 } catch (error) {73 return initialValue74 }75 })7677 const setValue = useCallback((value: T | ((val: T) => T)) => {78 try {79 const valueToStore = value instanceof Function ? value(storedValue) : value80 setStoredValue(valueToStore)81 window.localStorage.setItem(key, JSON.stringify(valueToStore))82 } catch (error) {83 console.error(error)84 }85 }, [key, storedValue])8687 return [storedValue, setValue] as const88}89```9091## Hook Naming Conventions92- **Data**: `useUsers`, `useUser`, `useProducts`93- **Forms**: `useUserForm`, `useProductForm`94- **UI State**: `useDisclosure`, `useToggle`, `useLocalStorage`95- **Business Logic**: `useAuth`, `useCart`, `useNotifications`9697## Hook Extraction Rules9899### Extract Logic When:100- Same logic used in 2+ components101- Component exceeds 100 lines due to logic102- Complex state management patterns103- API interaction patterns104105### Don't Extract When:106- Logic is component-specific107- Only used once108- Simple useState patterns109
Also in chihebnabil/lovable-boilerplate
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| chihebnabil/lovable-boilerplate.cursor/rules/design.mdc · 63 | Cursor rules | styleuido-not | 65/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.cursor/rules/forms.mdc · 63 | Cursor rules | setupstyledo-not | 73/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.cursor/rules/services.mdc · 63 | Cursor rules | archtypesdo-not | 73/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.cursor/rules/typescript.mdc · 63 | Cursor rules | setupstyletypessecurity+2 | 73/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/architecture.instructions.md · 63 | Copilot instructions | stylearchtypesdatabase+2 | 69/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/design.instructions.md · 63 | Copilot instructions | lint-formatstyleuido-not | 61/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/development.instructions.md · 63 | Copilot instructions | setupbuildtestlint-format+7 | 88/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/hooks.instructions.md · 63 | Copilot instructions | styleui | 54/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/lib.instructions.md · 63 | Copilot instructions | archtypesdo-not | 69/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/pages.instructions.md · 63 | Copilot instructions | archuido-not | 69/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/quality.instructions.md · 63 | Copilot instructions | lint-formatdeploymentdo-not | 63/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/reusable.instructions.md · 63 | Copilot instructions | uido-notagent-behaviour | 32/100 | 3 days ago | |
| chihebnabil/lovable-boilerplateCLAUDE.md · 63 | CLAUDE.md | setupbuildtestlint-format+5 | 89/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.cursor/rules/core.mdc · 63 | Cursor rules | buildlint-formatarchui+1 | 92/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/components.instructions.md · 63 | Copilot instructions | styleuido-not | 61/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.cursor/rules/components.mdc · 63 | Cursor rules | stylearchuido-not | 65/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.cursor/rules/quality.mdc · 63 | Cursor rules | buildlint-formatstyleui+3 | 88/100 | 3 days ago |
Diff against .cursor/rules/design.mdc Diff against .cursor/rules/forms.mdc Diff against .cursor/rules/services.mdc Diff against .cursor/rules/typescript.mdc Diff against .github/instructions/architecture.instructions.md Diff against .github/instructions/design.instructions.md Diff against .github/instructions/development.instructions.md Diff against .github/instructions/hooks.instructions.md Diff against .github/instructions/lib.instructions.md Diff against .github/instructions/pages.instructions.md Diff against .github/instructions/quality.instructions.md Diff against .github/instructions/reusable.instructions.md Diff against CLAUDE.md Diff against .cursor/rules/core.mdc Diff against .github/instructions/components.instructions.md Diff against .github/instructions/global.instructions.md Diff against .cursor/rules/components.mdc Diff against .cursor/rules/quality.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
