create-huenei-template 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/templates.js +7 -0
- package/dist/templates/cursor/.cursor/agents/config-drift-analyzer.md +152 -0
- package/dist/templates/cursor/.cursor/commands/actualizar-reglas.md +580 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/accessibility-reviewer.md +22 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/nextjs-code-reviewer.md +24 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/react-test-expert.md +32 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/security-auditor.md +25 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-component.md +97 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-page.md +95 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-prisma-model.md +66 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-server-action.md +89 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/auto-format.ts +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/auto-test-on-stop.ts +94 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/block-dangerous-commands.ts +120 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/ensure-tests-exist.ts +209 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/protect-sensitive-files.ts +101 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/session-context.ts +93 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/tsconfig.json +10 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/auth-patterns.mdc +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/code-quality.mdc +39 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/naming-conventions.mdc +32 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/nextjs-architecture.mdc +51 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/prisma-standards.mdc +53 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/react-conventions.mdc +52 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/testing-conventions.mdc +53 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/ui-stack.mdc +47 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/authjs-skills/SKILL.md +1149 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/SKILL.md +189 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/daisyUI5.skill +0 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/creating-components.md +412 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/data-display.md +341 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/feedback.md +240 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/input.md +283 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/layout.md +275 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/navigation.md +338 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/daisy-meta.ts +220 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/generate-daisy-safelist.ts +152 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/docker-expert/SKILL.md +413 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/nextjs-app-router-patterns/SKILL.md +537 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/SKILL.md +243 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-execute.md +75 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-pull.md +185 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-push.md +148 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-seed.md +191 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/debug.md +46 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/dev.md +157 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/format.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/generate.md +147 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/init.md +118 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-deploy.md +127 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-dev.md +143 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-diff.md +89 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-reset.md +72 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-resolve.md +57 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-status.md +65 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/studio.md +122 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/validate.md +53 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/SKILL.md +216 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/client-methods.md +221 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/constructor.md +185 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/filters.md +256 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/model-queries.md +281 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/query-options.md +276 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/raw-queries.md +194 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/relations.md +308 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/transactions.md +184 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/AGENTS.md +97 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/README.md +138 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/SKILL.md +116 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/assets/templates/_template.md +26 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/_sections.md +46 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-devtools-performance.md +69 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-formprovider-memo.md +78 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-testing-wrapper.md +63 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-complete-default-objects.md +66 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-separate-crud-operations.md +76 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-unique-fieldarray-per-name.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-use-field-id-as-key.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-virtualization-formprovider.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-avoid-double-registration.md +46 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-controller-field-props.md +56 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-local-state-combination.md +69 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-single-usecontroller-per-component.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-usecontroller-isolation.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-async-default-values.md +69 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-default-values.md +57 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-revalidate-mode.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-should-unregister.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-useeffect-dependency.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-validation-mode.md +51 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-avoid-isvalid-with-onsubmit.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-destructure-formstate.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-getfieldstate-for-single-field.md +49 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-subscribe-to-specific-fields.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-useformstate-isolation.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-mui-controller-pattern.md +59 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-form-import.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-select-wiring.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-value-transform.md +59 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-avoid-watch-in-render.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-deep-subscription.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-useformcontext-sparingly.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-default-value.md +50 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-over-watch.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-with-getvalues.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-watch-specific-fields.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-delay-error.md +52 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-dynamic-schema-factory.md +57 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-error-message-strategy.md +65 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-inline-vs-resolver.md +63 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-native-validation.md +60 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-resolver-caching.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/SKILL.md +713 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/references/api_reference.md +1121 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/references/best_practices.md +782 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/references/examples.md +940 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/SKILL.md +114 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-gc-time.md +93 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-invalidation.md +116 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-placeholder-vs-initial.md +156 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-stale-time.md +80 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/err-error-boundaries.md +150 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/inf-page-params.md +132 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-invalidate-queries.md +118 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-mutation-state.md +169 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-optimistic-updates.md +137 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/network-mode.md +179 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/parallel-use-queries.md +152 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/perf-select-transform.md +144 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/persist-queries.md +194 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/pf-intent-prefetch.md +143 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-array-structure.md +50 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-factory-pattern.md +102 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-hierarchical-organization.md +76 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-include-dependencies.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-serializable.md +93 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/query-cancellation.md +171 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/ssr-dehydration.md +158 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-table/SKILL.md +582 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/zod-4/SKILL.md +216 -0
- package/dist/templates/frontend/react-ssr/.dockerignore +14 -0
- package/dist/templates/frontend/react-ssr/.env.example +9 -0
- package/dist/templates/frontend/react-ssr/.husky/pre-commit +1 -0
- package/dist/templates/frontend/react-ssr/Dockerfile +41 -0
- package/dist/templates/frontend/react-ssr/README.md +121 -0
- package/dist/templates/frontend/react-ssr/components.json +22 -0
- package/dist/templates/frontend/react-ssr/docker-compose.yml +21 -0
- package/dist/templates/frontend/react-ssr/eslint.config.mjs +26 -0
- package/dist/templates/frontend/react-ssr/next.config.ts +7 -0
- package/dist/templates/frontend/react-ssr/package.json +86 -0
- package/dist/templates/frontend/react-ssr/postcss.config.mjs +5 -0
- package/dist/templates/frontend/react-ssr/prisma/schema.prisma +75 -0
- package/dist/templates/frontend/react-ssr/prisma/seed.ts +109 -0
- package/dist/templates/frontend/react-ssr/prisma.config.ts +17 -0
- package/dist/templates/frontend/react-ssr/skills-lock.json +65 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/badge.test.tsx +26 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/button.test.tsx +38 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/card.test.tsx +39 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/input.test.tsx +32 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/hooks/useLocalStorage.test.ts +53 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/lib/queryClient.test.ts +19 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/lib/utils.test.ts +24 -0
- package/dist/templates/frontend/react-ssr/src/actions/auth.ts +91 -0
- package/dist/templates/frontend/react-ssr/src/actions/contacto.ts +46 -0
- package/dist/templates/frontend/react-ssr/src/actions/proyectos.ts +159 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/dashboard-client.tsx +321 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/page.tsx +48 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/layout.tsx +34 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/perfil/page.tsx +85 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/page.tsx +23 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/proyectos-crud-client.tsx +472 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/ui-components/page.tsx +358 -0
- package/dist/templates/frontend/react-ssr/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/dist/templates/frontend/react-ssr/src/app/auth/iniciar-sesion/page.tsx +148 -0
- package/dist/templates/frontend/react-ssr/src/app/auth/recuperar-password/page.tsx +100 -0
- package/dist/templates/frontend/react-ssr/src/app/auth/registro/page.tsx +154 -0
- package/dist/templates/frontend/react-ssr/src/app/contacto/contacto-form.tsx +189 -0
- package/dist/templates/frontend/react-ssr/src/app/contacto/page.tsx +11 -0
- package/dist/templates/frontend/react-ssr/src/app/globals.css +99 -0
- package/dist/templates/frontend/react-ssr/src/app/layout.tsx +22 -0
- package/dist/templates/frontend/react-ssr/src/app/loading.tsx +7 -0
- package/dist/templates/frontend/react-ssr/src/app/not-found.tsx +14 -0
- package/dist/templates/frontend/react-ssr/src/app/page.tsx +331 -0
- package/dist/templates/frontend/react-ssr/src/app/proyectos/page.tsx +178 -0
- package/dist/templates/frontend/react-ssr/src/auth.ts +64 -0
- package/dist/templates/frontend/react-ssr/src/components/layout/navbar.tsx +68 -0
- package/dist/templates/frontend/react-ssr/src/components/layout/sidebar.tsx +109 -0
- package/dist/templates/frontend/react-ssr/src/components/layout/sign-out-button.tsx +16 -0
- package/dist/templates/frontend/react-ssr/src/components/providers.tsx +33 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/avatar.tsx +53 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/badge.tsx +42 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/breadcrumb.tsx +114 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/button.tsx +58 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/card.tsx +95 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/dialog.tsx +136 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/form.tsx +168 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/input.tsx +22 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/label.tsx +26 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/password-input.tsx +43 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/separator.tsx +30 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/table.tsx +240 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/tabs.tsx +76 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/textarea.tsx +21 -0
- package/dist/templates/frontend/react-ssr/src/data/dashboard.ts +179 -0
- package/dist/templates/frontend/react-ssr/src/hooks/useLocalStorage.ts +38 -0
- package/dist/templates/frontend/react-ssr/src/lib/prisma.ts +24 -0
- package/dist/templates/frontend/react-ssr/src/lib/queryClient.ts +25 -0
- package/dist/templates/frontend/react-ssr/src/lib/utils.ts +6 -0
- package/dist/templates/frontend/react-ssr/src/proxy.ts +31 -0
- package/dist/templates/frontend/react-ssr/src/test/mocks/next-navigation.ts +16 -0
- package/dist/templates/frontend/react-ssr/src/test/setup.ts +1 -0
- package/dist/templates/frontend/react-ssr/src/test/utils.tsx +30 -0
- package/dist/templates/frontend/react-ssr/src/types/index.ts +36 -0
- package/dist/templates/frontend/react-ssr/tsconfig.json +41 -0
- package/dist/templates/frontend/react-ssr/vitest.config.ts +41 -0
- package/package.json +1 -1
- package/templates/cursor/.cursor/agents/config-drift-analyzer.md +152 -0
- package/templates/cursor/.cursor/commands/actualizar-reglas.md +580 -0
- package/templates/frontend/react-ssr/.cursor/agents/accessibility-reviewer.md +22 -0
- package/templates/frontend/react-ssr/.cursor/agents/nextjs-code-reviewer.md +24 -0
- package/templates/frontend/react-ssr/.cursor/agents/react-test-expert.md +32 -0
- package/templates/frontend/react-ssr/.cursor/agents/security-auditor.md +25 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-component.md +97 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-page.md +95 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-prisma-model.md +66 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-server-action.md +89 -0
- package/templates/frontend/react-ssr/.cursor/hooks/auto-format.ts +64 -0
- package/templates/frontend/react-ssr/.cursor/hooks/auto-test-on-stop.ts +94 -0
- package/templates/frontend/react-ssr/.cursor/hooks/block-dangerous-commands.ts +120 -0
- package/templates/frontend/react-ssr/.cursor/hooks/ensure-tests-exist.ts +209 -0
- package/templates/frontend/react-ssr/.cursor/hooks/protect-sensitive-files.ts +101 -0
- package/templates/frontend/react-ssr/.cursor/hooks/session-context.ts +93 -0
- package/templates/frontend/react-ssr/.cursor/hooks/tsconfig.json +10 -0
- package/templates/frontend/react-ssr/.cursor/hooks.json +41 -0
- package/templates/frontend/react-ssr/.cursor/rules/auth-patterns.mdc +48 -0
- package/templates/frontend/react-ssr/.cursor/rules/code-quality.mdc +39 -0
- package/templates/frontend/react-ssr/.cursor/rules/naming-conventions.mdc +32 -0
- package/templates/frontend/react-ssr/.cursor/rules/nextjs-architecture.mdc +51 -0
- package/templates/frontend/react-ssr/.cursor/rules/prisma-standards.mdc +53 -0
- package/templates/frontend/react-ssr/.cursor/rules/react-conventions.mdc +52 -0
- package/templates/frontend/react-ssr/.cursor/rules/testing-conventions.mdc +53 -0
- package/templates/frontend/react-ssr/.cursor/rules/ui-stack.mdc +47 -0
- package/templates/frontend/react-ssr/.cursor/skills/authjs-skills/SKILL.md +1149 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/SKILL.md +189 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/daisyUI5.skill +0 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/creating-components.md +412 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/data-display.md +341 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/feedback.md +240 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/input.md +283 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/layout.md +275 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/navigation.md +338 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/daisy-meta.ts +220 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/generate-daisy-safelist.ts +152 -0
- package/templates/frontend/react-ssr/.cursor/skills/docker-expert/SKILL.md +413 -0
- package/templates/frontend/react-ssr/.cursor/skills/nextjs-app-router-patterns/SKILL.md +537 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/SKILL.md +243 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-execute.md +75 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-pull.md +185 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-push.md +148 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-seed.md +191 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/debug.md +46 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/dev.md +157 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/format.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/generate.md +147 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/init.md +118 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-deploy.md +127 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-dev.md +143 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-diff.md +89 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-reset.md +72 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-resolve.md +57 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-status.md +65 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/studio.md +122 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/validate.md +53 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/SKILL.md +216 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/client-methods.md +221 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/constructor.md +185 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/filters.md +256 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/model-queries.md +281 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/query-options.md +276 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/raw-queries.md +194 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/relations.md +308 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/transactions.md +184 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/AGENTS.md +97 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/README.md +138 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/SKILL.md +116 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/assets/templates/_template.md +26 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/_sections.md +46 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-devtools-performance.md +69 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-formprovider-memo.md +78 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-testing-wrapper.md +63 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-complete-default-objects.md +66 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-separate-crud-operations.md +76 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-unique-fieldarray-per-name.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-use-field-id-as-key.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-virtualization-formprovider.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-avoid-double-registration.md +46 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-controller-field-props.md +56 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-local-state-combination.md +69 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-single-usecontroller-per-component.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-usecontroller-isolation.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-async-default-values.md +69 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-default-values.md +57 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-revalidate-mode.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-should-unregister.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-useeffect-dependency.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-validation-mode.md +51 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-avoid-isvalid-with-onsubmit.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-destructure-formstate.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-getfieldstate-for-single-field.md +49 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-subscribe-to-specific-fields.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-useformstate-isolation.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-mui-controller-pattern.md +59 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-form-import.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-select-wiring.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-value-transform.md +59 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-avoid-watch-in-render.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-deep-subscription.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-useformcontext-sparingly.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-default-value.md +50 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-over-watch.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-with-getvalues.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-watch-specific-fields.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-delay-error.md +52 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-dynamic-schema-factory.md +57 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-error-message-strategy.md +65 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-inline-vs-resolver.md +63 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-native-validation.md +60 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-resolver-caching.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/SKILL.md +713 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/references/api_reference.md +1121 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/references/best_practices.md +782 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/references/examples.md +940 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/SKILL.md +114 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-gc-time.md +93 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-invalidation.md +116 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-placeholder-vs-initial.md +156 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-stale-time.md +80 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/err-error-boundaries.md +150 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/inf-page-params.md +132 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-invalidate-queries.md +118 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-mutation-state.md +169 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-optimistic-updates.md +137 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/network-mode.md +179 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/parallel-use-queries.md +152 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/perf-select-transform.md +144 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/persist-queries.md +194 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/pf-intent-prefetch.md +143 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-array-structure.md +50 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-factory-pattern.md +102 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-hierarchical-organization.md +76 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-include-dependencies.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-serializable.md +93 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/query-cancellation.md +171 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/ssr-dehydration.md +158 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-table/SKILL.md +582 -0
- package/templates/frontend/react-ssr/.cursor/skills/zod-4/SKILL.md +216 -0
- package/templates/frontend/react-ssr/.dockerignore +14 -0
- package/templates/frontend/react-ssr/.env.example +9 -0
- package/templates/frontend/react-ssr/.husky/pre-commit +1 -0
- package/templates/frontend/react-ssr/Dockerfile +41 -0
- package/templates/frontend/react-ssr/README.md +121 -0
- package/templates/frontend/react-ssr/components.json +22 -0
- package/templates/frontend/react-ssr/docker-compose.yml +21 -0
- package/templates/frontend/react-ssr/eslint.config.mjs +26 -0
- package/templates/frontend/react-ssr/next.config.ts +7 -0
- package/templates/frontend/react-ssr/package.json +86 -0
- package/templates/frontend/react-ssr/postcss.config.mjs +5 -0
- package/templates/frontend/react-ssr/prisma/schema.prisma +75 -0
- package/templates/frontend/react-ssr/prisma/seed.ts +109 -0
- package/templates/frontend/react-ssr/prisma.config.ts +17 -0
- package/templates/frontend/react-ssr/skills-lock.json +65 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/badge.test.tsx +26 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/button.test.tsx +38 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/card.test.tsx +39 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/input.test.tsx +32 -0
- package/templates/frontend/react-ssr/src/__tests__/hooks/useLocalStorage.test.ts +53 -0
- package/templates/frontend/react-ssr/src/__tests__/lib/queryClient.test.ts +19 -0
- package/templates/frontend/react-ssr/src/__tests__/lib/utils.test.ts +24 -0
- package/templates/frontend/react-ssr/src/actions/auth.ts +91 -0
- package/templates/frontend/react-ssr/src/actions/contacto.ts +46 -0
- package/templates/frontend/react-ssr/src/actions/proyectos.ts +159 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/dashboard-client.tsx +321 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/page.tsx +48 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/layout.tsx +34 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/perfil/page.tsx +85 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/page.tsx +23 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/proyectos-crud-client.tsx +472 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/ui-components/page.tsx +358 -0
- package/templates/frontend/react-ssr/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/templates/frontend/react-ssr/src/app/auth/iniciar-sesion/page.tsx +148 -0
- package/templates/frontend/react-ssr/src/app/auth/recuperar-password/page.tsx +100 -0
- package/templates/frontend/react-ssr/src/app/auth/registro/page.tsx +154 -0
- package/templates/frontend/react-ssr/src/app/contacto/contacto-form.tsx +189 -0
- package/templates/frontend/react-ssr/src/app/contacto/page.tsx +11 -0
- package/templates/frontend/react-ssr/src/app/globals.css +99 -0
- package/templates/frontend/react-ssr/src/app/layout.tsx +22 -0
- package/templates/frontend/react-ssr/src/app/loading.tsx +7 -0
- package/templates/frontend/react-ssr/src/app/not-found.tsx +14 -0
- package/templates/frontend/react-ssr/src/app/page.tsx +331 -0
- package/templates/frontend/react-ssr/src/app/proyectos/page.tsx +178 -0
- package/templates/frontend/react-ssr/src/auth.ts +64 -0
- package/templates/frontend/react-ssr/src/components/layout/navbar.tsx +68 -0
- package/templates/frontend/react-ssr/src/components/layout/sidebar.tsx +109 -0
- package/templates/frontend/react-ssr/src/components/layout/sign-out-button.tsx +16 -0
- package/templates/frontend/react-ssr/src/components/providers.tsx +33 -0
- package/templates/frontend/react-ssr/src/components/ui/avatar.tsx +53 -0
- package/templates/frontend/react-ssr/src/components/ui/badge.tsx +42 -0
- package/templates/frontend/react-ssr/src/components/ui/breadcrumb.tsx +114 -0
- package/templates/frontend/react-ssr/src/components/ui/button.tsx +58 -0
- package/templates/frontend/react-ssr/src/components/ui/card.tsx +95 -0
- package/templates/frontend/react-ssr/src/components/ui/dialog.tsx +136 -0
- package/templates/frontend/react-ssr/src/components/ui/form.tsx +168 -0
- package/templates/frontend/react-ssr/src/components/ui/input.tsx +22 -0
- package/templates/frontend/react-ssr/src/components/ui/label.tsx +26 -0
- package/templates/frontend/react-ssr/src/components/ui/password-input.tsx +43 -0
- package/templates/frontend/react-ssr/src/components/ui/separator.tsx +30 -0
- package/templates/frontend/react-ssr/src/components/ui/table.tsx +240 -0
- package/templates/frontend/react-ssr/src/components/ui/tabs.tsx +76 -0
- package/templates/frontend/react-ssr/src/components/ui/textarea.tsx +21 -0
- package/templates/frontend/react-ssr/src/data/dashboard.ts +179 -0
- package/templates/frontend/react-ssr/src/hooks/useLocalStorage.ts +38 -0
- package/templates/frontend/react-ssr/src/lib/prisma.ts +24 -0
- package/templates/frontend/react-ssr/src/lib/queryClient.ts +25 -0
- package/templates/frontend/react-ssr/src/lib/utils.ts +6 -0
- package/templates/frontend/react-ssr/src/proxy.ts +31 -0
- package/templates/frontend/react-ssr/src/test/mocks/next-navigation.ts +16 -0
- package/templates/frontend/react-ssr/src/test/setup.ts +1 -0
- package/templates/frontend/react-ssr/src/test/utils.tsx +30 -0
- package/templates/frontend/react-ssr/src/types/index.ts +36 -0
- package/templates/frontend/react-ssr/tsconfig.json +41 -0
- package/templates/frontend/react-ssr/vitest.config.ts +41 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Avoid Calling watch() in Render for One-Time Reads
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: prevents unnecessary subscriptions and re-renders
|
|
5
|
+
tags: sub, watch, getValues, render, one-time-read
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Avoid Calling watch() in Render for One-Time Reads
|
|
9
|
+
|
|
10
|
+
If you only need to read a value once (not subscribe to changes), use `getValues()` instead of `watch()`. Calling watch() creates a subscription that triggers re-renders on every change.
|
|
11
|
+
|
|
12
|
+
**Incorrect (watch creates subscription for one-time read):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function SubmitButton() {
|
|
16
|
+
const { watch, handleSubmit, formState: { isValid } } = useForm()
|
|
17
|
+
|
|
18
|
+
const handleClick = () => {
|
|
19
|
+
const email = watch('email') // Creates subscription, but we only need current value
|
|
20
|
+
analytics.track('form_submit_attempt', { email })
|
|
21
|
+
handleSubmit(onSubmit)()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return <button onClick={handleClick} disabled={!isValid}>Submit</button>
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Correct (getValues for one-time read):**
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
function SubmitButton() {
|
|
32
|
+
const { getValues, handleSubmit, formState: { isValid } } = useForm()
|
|
33
|
+
|
|
34
|
+
const handleClick = () => {
|
|
35
|
+
const email = getValues('email') // No subscription, just current value
|
|
36
|
+
analytics.track('form_submit_attempt', { email })
|
|
37
|
+
handleSubmit(onSubmit)()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return <button onClick={handleClick} disabled={!isValid}>Submit</button>
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**When to use each:**
|
|
45
|
+
- `watch()`: Need to react to value changes (display, conditional rendering)
|
|
46
|
+
- `getValues()`: Need current value at a point in time (event handlers, submit)
|
|
47
|
+
|
|
48
|
+
Reference: [useForm - getValues](https://react-hook-form.com/docs/useform/getvalues)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Subscribe Deep in Component Tree Where Data Is Needed
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: prevents parent re-renders from propagating to unrelated children
|
|
5
|
+
tags: sub, subscription, component-tree, re-renders
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Subscribe Deep in Component Tree Where Data Is Needed
|
|
9
|
+
|
|
10
|
+
Subscribe to form values as deep in the component tree as possible, where the data is actually used. This isolates re-renders to the specific component that needs the value.
|
|
11
|
+
|
|
12
|
+
**Incorrect (subscription at parent re-renders all children):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function CheckoutPage() {
|
|
16
|
+
const { control, register, handleSubmit } = useForm()
|
|
17
|
+
const paymentMethod = useWatch({ control, name: 'paymentMethod' }) // Parent subscribes
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
21
|
+
<ShippingSection register={register} /> {/* Re-renders on paymentMethod change */}
|
|
22
|
+
<BillingSection register={register} /> {/* Re-renders on paymentMethod change */}
|
|
23
|
+
<PaymentSection
|
|
24
|
+
register={register}
|
|
25
|
+
paymentMethod={paymentMethod} {/* Prop drilling */}
|
|
26
|
+
/>
|
|
27
|
+
</form>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Correct (subscription at leaf component isolates re-renders):**
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
function CheckoutPage() {
|
|
36
|
+
const { control, register, handleSubmit } = useForm()
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
40
|
+
<ShippingSection register={register} /> {/* Never re-renders for payment */}
|
|
41
|
+
<BillingSection register={register} /> {/* Never re-renders for payment */}
|
|
42
|
+
<PaymentSection register={register} control={control} />
|
|
43
|
+
</form>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function PaymentSection({ register, control }: PaymentSectionProps) {
|
|
48
|
+
const paymentMethod = useWatch({ control, name: 'paymentMethod' }) // Only this re-renders
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
<select {...register('paymentMethod')}>
|
|
53
|
+
<option value="card">Credit Card</option>
|
|
54
|
+
<option value="paypal">PayPal</option>
|
|
55
|
+
</select>
|
|
56
|
+
{paymentMethod === 'card' && <CardFields register={register} />}
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Reference: [useWatch](https://react-hook-form.com/docs/usewatch)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use useFormContext Sparingly for Deep Nesting
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: reduces prop drilling but increases implicit dependencies
|
|
5
|
+
tags: sub, useFormContext, FormProvider, prop-drilling
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use useFormContext Sparingly for Deep Nesting
|
|
9
|
+
|
|
10
|
+
useFormContext eliminates prop drilling by accessing form methods via context, but creates implicit dependencies that are harder to track. Use it for deeply nested components; prefer explicit props for shallow nesting.
|
|
11
|
+
|
|
12
|
+
**Incorrect (useFormContext for shallow nesting):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function ContactForm() {
|
|
16
|
+
const methods = useForm()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<FormProvider {...methods}>
|
|
20
|
+
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
21
|
+
<NameInput /> {/* One level deep, context overhead not needed */}
|
|
22
|
+
<EmailInput />
|
|
23
|
+
</form>
|
|
24
|
+
</FormProvider>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function NameInput() {
|
|
29
|
+
const { register } = useFormContext() // Implicit dependency
|
|
30
|
+
return <input {...register('name')} />
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Correct (explicit props for shallow nesting):**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
function ContactForm() {
|
|
38
|
+
const { register, handleSubmit } = useForm()
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
42
|
+
<NameInput register={register} /> {/* Explicit dependency */}
|
|
43
|
+
<EmailInput register={register} />
|
|
44
|
+
</form>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function NameInput({ register }: { register: UseFormRegister<ContactFormData> }) {
|
|
49
|
+
return <input {...register('name')} />
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**When to use useFormContext:**
|
|
54
|
+
- Components nested 3+ levels deep
|
|
55
|
+
- Shared components used across multiple forms
|
|
56
|
+
- Complex form sections with many fields
|
|
57
|
+
|
|
58
|
+
Reference: [useFormContext](https://react-hook-form.com/docs/useformcontext)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Provide defaultValue to useWatch for Initial Render
|
|
3
|
+
impact: MEDIUM-HIGH
|
|
4
|
+
impactDescription: prevents undefined flash on initial render
|
|
5
|
+
tags: sub, useWatch, default-value, hydration
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Provide defaultValue to useWatch for Initial Render
|
|
9
|
+
|
|
10
|
+
useWatch returns undefined on the first render before the subscription is established. Provide a defaultValue to prevent undefined checks and potential UI flicker.
|
|
11
|
+
|
|
12
|
+
**Incorrect (undefined on first render):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function PriceDisplay({ control }: { control: Control<OrderForm> }) {
|
|
16
|
+
const quantity = useWatch({ control, name: 'quantity' })
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
{quantity !== undefined ? ( // Undefined check required
|
|
21
|
+
<span>Quantity: {quantity}</span>
|
|
22
|
+
) : (
|
|
23
|
+
<span>Loading...</span> // Flash of loading state
|
|
24
|
+
)}
|
|
25
|
+
</div>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Correct (defaultValue prevents undefined):**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
function PriceDisplay({ control }: { control: Control<OrderForm> }) {
|
|
34
|
+
const quantity = useWatch({
|
|
35
|
+
control,
|
|
36
|
+
name: 'quantity',
|
|
37
|
+
defaultValue: 1, // Immediate value, no undefined check needed
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<span>Quantity: {quantity}</span>
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Note:** defaultValue should match the type expected by your form schema to maintain type safety.
|
|
49
|
+
|
|
50
|
+
Reference: [useWatch](https://react-hook-form.com/docs/usewatch)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use useWatch Instead of watch for Isolated Re-renders
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: reduces re-renders by 10-50× in complex forms with multiple watchers
|
|
5
|
+
tags: sub, useWatch, watch, re-renders, subscription
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use useWatch Instead of watch for Isolated Re-renders
|
|
9
|
+
|
|
10
|
+
The `watch()` method triggers re-renders at the useForm hook level, affecting the entire form component. Use `useWatch()` in child components to isolate re-renders to only the components that need the watched value.
|
|
11
|
+
|
|
12
|
+
**Incorrect (watch at root causes entire form to re-render):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function CheckoutForm() {
|
|
16
|
+
const { register, watch, handleSubmit } = useForm()
|
|
17
|
+
const shippingMethod = watch('shippingMethod') // Every change re-renders entire form
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
21
|
+
<select {...register('shippingMethod')}>
|
|
22
|
+
<option value="standard">Standard</option>
|
|
23
|
+
<option value="express">Express</option>
|
|
24
|
+
</select>
|
|
25
|
+
<ShippingCost method={shippingMethod} />
|
|
26
|
+
<input {...register('address')} />
|
|
27
|
+
<input {...register('city')} />
|
|
28
|
+
</form>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Correct (useWatch isolates re-render to child component):**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
function CheckoutForm() {
|
|
37
|
+
const { register, handleSubmit, control } = useForm()
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
41
|
+
<select {...register('shippingMethod')}>
|
|
42
|
+
<option value="standard">Standard</option>
|
|
43
|
+
<option value="express">Express</option>
|
|
44
|
+
</select>
|
|
45
|
+
<ShippingCostDisplay control={control} /> {/* Only this re-renders */}
|
|
46
|
+
<input {...register('address')} />
|
|
47
|
+
<input {...register('city')} />
|
|
48
|
+
</form>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function ShippingCostDisplay({ control }: { control: Control<CheckoutFormData> }) {
|
|
53
|
+
const shippingMethod = useWatch({ control, name: 'shippingMethod' })
|
|
54
|
+
return <ShippingCost method={shippingMethod} />
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Reference: [useWatch](https://react-hook-form.com/docs/usewatch)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Combine useWatch with getValues for Timing Safety
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: prevents missed updates due to subscription timing
|
|
5
|
+
tags: sub, useWatch, getValues, timing, subscription
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Combine useWatch with getValues for Timing Safety
|
|
9
|
+
|
|
10
|
+
If `setValue()` is called before useWatch establishes its subscription, the update is missed. Combine useWatch with getValues to guarantee no updates are lost.
|
|
11
|
+
|
|
12
|
+
**Incorrect (setValue before subscription misses update):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function PrefillableForm() {
|
|
16
|
+
const { setValue, control } = useForm()
|
|
17
|
+
const couponCode = useWatch({ control, name: 'couponCode' })
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const savedCoupon = localStorage.getItem('savedCoupon')
|
|
21
|
+
if (savedCoupon) {
|
|
22
|
+
setValue('couponCode', savedCoupon) // May fire before useWatch subscription
|
|
23
|
+
}
|
|
24
|
+
}, [setValue])
|
|
25
|
+
|
|
26
|
+
return <div>Applied coupon: {couponCode}</div> {/* May show stale value */}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Correct (merge subscription with current values):**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
function PrefillableForm() {
|
|
34
|
+
const { setValue, control, getValues } = useForm()
|
|
35
|
+
|
|
36
|
+
const useFormValues = () => ({
|
|
37
|
+
...useWatch({ control }),
|
|
38
|
+
...getValues(), // Fallback ensures no missed values
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const { couponCode } = useFormValues()
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const savedCoupon = localStorage.getItem('savedCoupon')
|
|
45
|
+
if (savedCoupon) {
|
|
46
|
+
setValue('couponCode', savedCoupon)
|
|
47
|
+
}
|
|
48
|
+
}, [setValue])
|
|
49
|
+
|
|
50
|
+
return <div>Applied coupon: {couponCode}</div> {/* Always shows current value */}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Reference: [useWatch](https://react-hook-form.com/docs/usewatch)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Watch Specific Fields Instead of Entire Form
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: reduces re-renders from N fields to 1 field change
|
|
5
|
+
tags: sub, watch, specific-fields, re-renders
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Watch Specific Fields Instead of Entire Form
|
|
9
|
+
|
|
10
|
+
Calling `watch()` without arguments subscribes to ALL form fields, causing re-renders on any field change. Always specify the field names you need.
|
|
11
|
+
|
|
12
|
+
**Incorrect (watches all fields, re-renders on any change):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function OrderForm() {
|
|
16
|
+
const { register, watch, handleSubmit } = useForm()
|
|
17
|
+
const formValues = watch() // Re-renders when ANY field changes
|
|
18
|
+
|
|
19
|
+
const total = calculateTotal(formValues.quantity, formValues.price)
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
23
|
+
<input {...register('customerName')} /> {/* Changes here trigger total recalc */}
|
|
24
|
+
<input {...register('email')} /> {/* Changes here trigger total recalc */}
|
|
25
|
+
<input {...register('quantity', { valueAsNumber: true })} />
|
|
26
|
+
<input {...register('price', { valueAsNumber: true })} />
|
|
27
|
+
<div>Total: ${total}</div>
|
|
28
|
+
</form>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Correct (watches only needed fields):**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
function OrderForm() {
|
|
37
|
+
const { register, watch, handleSubmit } = useForm()
|
|
38
|
+
const [quantity, price] = watch(['quantity', 'price']) // Only re-renders when these change
|
|
39
|
+
|
|
40
|
+
const total = calculateTotal(quantity, price)
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
44
|
+
<input {...register('customerName')} /> {/* No re-render on change */}
|
|
45
|
+
<input {...register('email')} /> {/* No re-render on change */}
|
|
46
|
+
<input {...register('quantity', { valueAsNumber: true })} />
|
|
47
|
+
<input {...register('price', { valueAsNumber: true })} />
|
|
48
|
+
<div>Total: ${total}</div>
|
|
49
|
+
</form>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Reference: [useForm - watch](https://react-hook-form.com/docs/useform/watch)
|
package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-delay-error.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use delayError to Debounce Rapid Error Display
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: reduces UI flicker during fast typing validation
|
|
5
|
+
tags: valid, delayError, debounce, user-experience
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use delayError to Debounce Rapid Error Display
|
|
9
|
+
|
|
10
|
+
When using `onChange` mode, errors appear and disappear rapidly as users type. Use `delayError` to add a small delay, preventing UI flicker while still providing timely feedback.
|
|
11
|
+
|
|
12
|
+
**Incorrect (errors flash rapidly during typing):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function SearchForm() {
|
|
16
|
+
const { register, formState: { errors } } = useForm({
|
|
17
|
+
mode: 'onChange',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<form>
|
|
22
|
+
<input {...register('query', { minLength: 3 })} />
|
|
23
|
+
{errors.query && <span>Min 3 characters</span>} {/* Flashes on/off rapidly */}
|
|
24
|
+
</form>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Correct (error display debounced):**
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
function SearchForm() {
|
|
33
|
+
const { register, formState: { errors } } = useForm({
|
|
34
|
+
mode: 'onChange',
|
|
35
|
+
delayError: 300, // 300ms delay before showing errors
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<form>
|
|
40
|
+
<input {...register('query', { minLength: 3 })} />
|
|
41
|
+
{errors.query && <span>Min 3 characters</span>} {/* Appears after 300ms delay */}
|
|
42
|
+
</form>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**When to use:**
|
|
48
|
+
- Real-time validation with `onChange` mode
|
|
49
|
+
- Fields with character count requirements
|
|
50
|
+
- Search inputs with minimum length
|
|
51
|
+
|
|
52
|
+
Reference: [useForm - delayError](https://react-hook-form.com/docs/useform)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Schema Factory for Dynamic Validation
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: enables context-dependent validation without render-time schema creation
|
|
5
|
+
tags: valid, schema, factory, dynamic, conditional
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Schema Factory for Dynamic Validation
|
|
9
|
+
|
|
10
|
+
When validation rules depend on runtime context (user role, feature flags), use a factory function to create schemas. This keeps schema creation outside the render cycle while allowing dynamic rules.
|
|
11
|
+
|
|
12
|
+
**Incorrect (schema recreated in component based on props):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function OrderForm({ maxQuantity }: { maxQuantity: number }) {
|
|
16
|
+
const { register, handleSubmit } = useForm({
|
|
17
|
+
resolver: zodResolver(
|
|
18
|
+
z.object({
|
|
19
|
+
quantity: z.number().max(maxQuantity), // Recreated when maxQuantity changes
|
|
20
|
+
notes: z.string().optional(),
|
|
21
|
+
})
|
|
22
|
+
),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
27
|
+
<input {...register('quantity', { valueAsNumber: true })} />
|
|
28
|
+
</form>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Correct (factory function creates schema outside render):**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
const createOrderSchema = (maxQuantity: number) =>
|
|
37
|
+
z.object({
|
|
38
|
+
quantity: z.number().max(maxQuantity, `Maximum ${maxQuantity} items`),
|
|
39
|
+
notes: z.string().optional(),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
function OrderForm({ maxQuantity }: { maxQuantity: number }) {
|
|
43
|
+
const schema = useMemo(() => createOrderSchema(maxQuantity), [maxQuantity])
|
|
44
|
+
|
|
45
|
+
const { register, handleSubmit } = useForm({
|
|
46
|
+
resolver: zodResolver(schema),
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
51
|
+
<input {...register('quantity', { valueAsNumber: true })} />
|
|
52
|
+
</form>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Reference: [React Hook Form Resolvers](https://github.com/react-hook-form/resolvers)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Access Errors via Optional Chaining or Lodash Get
|
|
3
|
+
impact: MEDIUM-HIGH
|
|
4
|
+
impactDescription: prevents runtime errors from undefined nested properties
|
|
5
|
+
tags: valid, errors, optional-chaining, nested-fields
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Access Errors via Optional Chaining or Lodash Get
|
|
9
|
+
|
|
10
|
+
Error objects can have deeply nested paths for nested fields. Use optional chaining or lodash `get()` to safely access error messages without runtime errors.
|
|
11
|
+
|
|
12
|
+
**Incorrect (direct access throws on undefined):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function AddressForm() {
|
|
16
|
+
const { register, formState: { errors } } = useForm()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<form>
|
|
20
|
+
<input {...register('address.street', { required: true })} />
|
|
21
|
+
<span>{errors.address.street.message}</span> {/* Throws if address undefined */}
|
|
22
|
+
|
|
23
|
+
<input {...register('address.city', { required: true })} />
|
|
24
|
+
<span>{errors.address.city.message}</span> {/* Throws if address undefined */}
|
|
25
|
+
</form>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Correct (optional chaining for safe access):**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
function AddressForm() {
|
|
34
|
+
const { register, formState: { errors } } = useForm()
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<form>
|
|
38
|
+
<input {...register('address.street', { required: true })} />
|
|
39
|
+
<span>{errors.address?.street?.message}</span> {/* Safe access */}
|
|
40
|
+
|
|
41
|
+
<input {...register('address.city', { required: true })} />
|
|
42
|
+
<span>{errors.address?.city?.message}</span> {/* Safe access */}
|
|
43
|
+
</form>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Alternative (lodash get for complex paths):**
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { get } from 'lodash'
|
|
52
|
+
|
|
53
|
+
function AddressForm() {
|
|
54
|
+
const { register, formState: { errors } } = useForm()
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<form>
|
|
58
|
+
<input {...register('address.street', { required: true })} />
|
|
59
|
+
<span>{get(errors, 'address.street.message')}</span>
|
|
60
|
+
</form>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Reference: [React Hook Form - Advanced Usage](https://react-hook-form.com/advanced-usage)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Prefer Resolver Over Inline Validation for Complex Rules
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: centralizes validation logic and enables type inference
|
|
5
|
+
tags: valid, resolver, inline-validation, schema
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Prefer Resolver Over Inline Validation for Complex Rules
|
|
9
|
+
|
|
10
|
+
Inline validation rules in `register()` are convenient for simple cases, but resolvers (Zod, Yup) provide better type safety, centralized logic, and cross-field validation capabilities.
|
|
11
|
+
|
|
12
|
+
**Incorrect (complex inline validation scattered across inputs):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function CheckoutForm() {
|
|
16
|
+
const { register, handleSubmit, watch } = useForm()
|
|
17
|
+
const billingAddressSame = watch('billingAddressSame')
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
21
|
+
<input {...register('email', {
|
|
22
|
+
required: 'Email required',
|
|
23
|
+
pattern: { value: /^\S+@\S+$/i, message: 'Invalid email' },
|
|
24
|
+
})} />
|
|
25
|
+
<input {...register('billingAddressSame')} type="checkbox" />
|
|
26
|
+
<input {...register('billingStreet', {
|
|
27
|
+
required: !billingAddressSame && 'Street required', // Cross-field logic inline
|
|
28
|
+
})} />
|
|
29
|
+
</form>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Correct (resolver centralizes all validation):**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const checkoutSchema = z.object({
|
|
38
|
+
email: z.string().email('Invalid email'),
|
|
39
|
+
billingAddressSame: z.boolean(),
|
|
40
|
+
billingStreet: z.string().optional(),
|
|
41
|
+
}).refine(
|
|
42
|
+
(data) => data.billingAddressSame || data.billingStreet,
|
|
43
|
+
{ message: 'Street required', path: ['billingStreet'] }
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
type CheckoutFormData = z.infer<typeof checkoutSchema>
|
|
47
|
+
|
|
48
|
+
function CheckoutForm() {
|
|
49
|
+
const { register, handleSubmit } = useForm<CheckoutFormData>({
|
|
50
|
+
resolver: zodResolver(checkoutSchema),
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
55
|
+
<input {...register('email')} />
|
|
56
|
+
<input {...register('billingAddressSame')} type="checkbox" />
|
|
57
|
+
<input {...register('billingStreet')} />
|
|
58
|
+
</form>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Reference: [React Hook Form Resolvers](https://github.com/react-hook-form/resolvers)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Consider Native Validation for Simple Forms
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: reduces JavaScript validation overhead for basic constraints
|
|
5
|
+
tags: valid, native-validation, browser, performance
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Consider Native Validation for Simple Forms
|
|
9
|
+
|
|
10
|
+
For simple forms with basic constraints (required, minLength, pattern), browser-native validation eliminates JavaScript validation overhead. Enable with `shouldUseNativeValidation`.
|
|
11
|
+
|
|
12
|
+
**Incorrect (JavaScript validates simple constraints):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
function NewsletterForm() {
|
|
16
|
+
const { register, handleSubmit, formState: { errors } } = useForm()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
20
|
+
<input
|
|
21
|
+
{...register('email', {
|
|
22
|
+
required: 'Email required',
|
|
23
|
+
pattern: { value: /^\S+@\S+$/i, message: 'Invalid email' },
|
|
24
|
+
})}
|
|
25
|
+
type="email"
|
|
26
|
+
/>
|
|
27
|
+
{errors.email && <span>{errors.email.message}</span>}
|
|
28
|
+
<button type="submit">Subscribe</button>
|
|
29
|
+
</form>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Correct (browser handles validation natively):**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
function NewsletterForm() {
|
|
38
|
+
const { register, handleSubmit } = useForm({
|
|
39
|
+
shouldUseNativeValidation: true,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
44
|
+
<input
|
|
45
|
+
{...register('email', { required: true })}
|
|
46
|
+
type="email" // Browser validates email format
|
|
47
|
+
required // Browser shows native required message
|
|
48
|
+
/>
|
|
49
|
+
<button type="submit">Subscribe</button>
|
|
50
|
+
</form>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**When NOT to use:**
|
|
56
|
+
- Custom error message styling required
|
|
57
|
+
- Complex cross-field validation
|
|
58
|
+
- Need consistent UX across browsers
|
|
59
|
+
|
|
60
|
+
Reference: [useForm - shouldUseNativeValidation](https://react-hook-form.com/docs/useform)
|