create-huenei-template 0.2.14 → 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/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/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
package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/SKILL.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tanstack-query-best-practices
|
|
3
|
+
description: TanStack Query (React Query) best practices for data fetching, caching, mutations, and server state management. Activate when building data-driven React applications with server state.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TanStack Query Best Practices
|
|
7
|
+
|
|
8
|
+
Comprehensive guidelines for implementing TanStack Query (React Query) patterns in React applications. These rules optimize data fetching, caching, mutations, and server state synchronization.
|
|
9
|
+
|
|
10
|
+
## When to Apply
|
|
11
|
+
|
|
12
|
+
- Creating new data fetching logic
|
|
13
|
+
- Setting up query configurations
|
|
14
|
+
- Implementing mutations and optimistic updates
|
|
15
|
+
- Configuring caching strategies
|
|
16
|
+
- Integrating with SSR/SSG
|
|
17
|
+
- Refactoring existing data fetching code
|
|
18
|
+
|
|
19
|
+
## Rule Categories by Priority
|
|
20
|
+
|
|
21
|
+
| Priority | Category | Rules | Impact |
|
|
22
|
+
|----------|----------|-------|--------|
|
|
23
|
+
| CRITICAL | Query Keys | 5 rules | Prevents cache bugs and data inconsistencies |
|
|
24
|
+
| CRITICAL | Caching | 5 rules | Optimizes performance and data freshness |
|
|
25
|
+
| HIGH | Mutations | 6 rules | Ensures data integrity and UI consistency |
|
|
26
|
+
| HIGH | Error Handling | 3 rules | Prevents poor user experiences |
|
|
27
|
+
| MEDIUM | Prefetching | 4 rules | Improves perceived performance |
|
|
28
|
+
| MEDIUM | Parallel Queries | 2 rules | Enables dynamic parallel fetching |
|
|
29
|
+
| MEDIUM | Infinite Queries | 3 rules | Prevents pagination bugs |
|
|
30
|
+
| MEDIUM | SSR Integration | 4 rules | Enables proper hydration |
|
|
31
|
+
| LOW | Performance | 4 rules | Reduces unnecessary re-renders |
|
|
32
|
+
| LOW | Offline Support | 2 rules | Enables offline-first patterns |
|
|
33
|
+
|
|
34
|
+
## Quick Reference
|
|
35
|
+
|
|
36
|
+
### Query Keys (Prefix: `qk-`)
|
|
37
|
+
|
|
38
|
+
- `qk-array-structure` — Always use arrays for query keys
|
|
39
|
+
- `qk-include-dependencies` — Include all variables the query depends on
|
|
40
|
+
- `qk-hierarchical-organization` — Organize keys hierarchically (entity → id → filters)
|
|
41
|
+
- `qk-factory-pattern` — Use query key factories for complex applications
|
|
42
|
+
- `qk-serializable` — Ensure all key parts are JSON-serializable
|
|
43
|
+
|
|
44
|
+
### Caching (Prefix: `cache-`)
|
|
45
|
+
|
|
46
|
+
- `cache-stale-time` — Set appropriate staleTime based on data volatility
|
|
47
|
+
- `cache-gc-time` — Configure gcTime for inactive query retention
|
|
48
|
+
- `cache-defaults` — Set sensible defaults at QueryClient level
|
|
49
|
+
- `cache-invalidation` — Use targeted invalidation over broad patterns
|
|
50
|
+
- `cache-placeholder-vs-initial` — Understand placeholder vs initial data differences
|
|
51
|
+
|
|
52
|
+
### Mutations (Prefix: `mut-`)
|
|
53
|
+
|
|
54
|
+
- `mut-invalidate-queries` — Always invalidate related queries after mutations
|
|
55
|
+
- `mut-optimistic-updates` — Implement optimistic updates for responsive UI
|
|
56
|
+
- `mut-rollback-context` — Provide rollback context from onMutate
|
|
57
|
+
- `mut-error-handling` — Handle mutation errors gracefully
|
|
58
|
+
- `mut-loading-states` — Use isPending for mutation loading states
|
|
59
|
+
- `mut-mutation-state` — Use useMutationState for cross-component tracking
|
|
60
|
+
|
|
61
|
+
### Error Handling (Prefix: `err-`)
|
|
62
|
+
|
|
63
|
+
- `err-error-boundaries` — Use error boundaries with useQueryErrorResetBoundary
|
|
64
|
+
- `err-retry-config` — Configure retry logic appropriately
|
|
65
|
+
- `err-fallback-data` — Provide fallback data when appropriate
|
|
66
|
+
|
|
67
|
+
### Prefetching (Prefix: `pf-`)
|
|
68
|
+
|
|
69
|
+
- `pf-intent-prefetch` — Prefetch on user intent (hover, focus)
|
|
70
|
+
- `pf-route-prefetch` — Prefetch data during route transitions
|
|
71
|
+
- `pf-stale-time-config` — Set staleTime when prefetching
|
|
72
|
+
- `pf-ensure-query-data` — Use ensureQueryData for conditional prefetching
|
|
73
|
+
|
|
74
|
+
### Infinite Queries (Prefix: `inf-`)
|
|
75
|
+
|
|
76
|
+
- `inf-page-params` — Always provide getNextPageParam
|
|
77
|
+
- `inf-loading-guards` — Check isFetchingNextPage before fetching more
|
|
78
|
+
- `inf-max-pages` — Consider maxPages for large datasets
|
|
79
|
+
|
|
80
|
+
### SSR Integration (Prefix: `ssr-`)
|
|
81
|
+
|
|
82
|
+
- `ssr-dehydration` — Use dehydrate/hydrate pattern for SSR
|
|
83
|
+
- `ssr-client-per-request` — Create QueryClient per request
|
|
84
|
+
- `ssr-stale-time-server` — Set higher staleTime on server
|
|
85
|
+
- `ssr-hydration-boundary` — Wrap with HydrationBoundary
|
|
86
|
+
|
|
87
|
+
### Parallel Queries (Prefix: `parallel-`)
|
|
88
|
+
|
|
89
|
+
- `parallel-use-queries` — Use useQueries for dynamic parallel queries
|
|
90
|
+
- `query-cancellation` — Implement query cancellation properly
|
|
91
|
+
|
|
92
|
+
### Performance (Prefix: `perf-`)
|
|
93
|
+
|
|
94
|
+
- `perf-select-transform` — Use select to transform/filter data
|
|
95
|
+
- `perf-structural-sharing` — Leverage structural sharing
|
|
96
|
+
- `perf-notify-change-props` — Limit re-renders with notifyOnChangeProps
|
|
97
|
+
- `perf-placeholder-data` — Use placeholderData for instant UI
|
|
98
|
+
|
|
99
|
+
### Offline Support (Prefix: `offline-`)
|
|
100
|
+
|
|
101
|
+
- `network-mode` — Configure network mode for offline support
|
|
102
|
+
- `persist-queries` — Configure query persistence for offline support
|
|
103
|
+
|
|
104
|
+
## How to Use
|
|
105
|
+
|
|
106
|
+
Each rule file in the `rules/` directory contains:
|
|
107
|
+
1. **Explanation** — Why this pattern matters
|
|
108
|
+
2. **Bad Example** — Anti-pattern to avoid
|
|
109
|
+
3. **Good Example** — Recommended implementation
|
|
110
|
+
4. **Context** — When to apply or skip this rule
|
|
111
|
+
|
|
112
|
+
## Full Reference
|
|
113
|
+
|
|
114
|
+
See individual rule files in `rules/` directory for detailed guidance and code examples.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# cache-gc-time: Configure gcTime for Inactive Query Retention
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
`gcTime` (garbage collection time, formerly `cacheTime`) controls how long inactive queries remain in the cache before being garbage collected. Default is 5 minutes. Configure based on your navigation patterns and memory constraints.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Not considering gcTime for frequently revisited pages
|
|
13
|
+
const { data } = useQuery({
|
|
14
|
+
queryKey: ['dashboard-stats'],
|
|
15
|
+
queryFn: fetchDashboardStats,
|
|
16
|
+
// Default gcTime of 5 minutes - might be too short for frequently revisited data
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Setting gcTime too high without consideration
|
|
20
|
+
const queryClient = new QueryClient({
|
|
21
|
+
defaultOptions: {
|
|
22
|
+
queries: {
|
|
23
|
+
gcTime: Infinity, // Never garbage collect - potential memory leak
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Setting gcTime to 0 - cache is immediately removed
|
|
29
|
+
const { data } = useQuery({
|
|
30
|
+
queryKey: ['user-data'],
|
|
31
|
+
queryFn: fetchUserData,
|
|
32
|
+
gcTime: 0, // Loses cache benefits entirely
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Good Example
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// Longer gcTime for frequently revisited data
|
|
40
|
+
const { data } = useQuery({
|
|
41
|
+
queryKey: ['dashboard-stats'],
|
|
42
|
+
queryFn: fetchDashboardStats,
|
|
43
|
+
gcTime: 30 * 60 * 1000, // 30 minutes - user returns to dashboard often
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Shorter gcTime for rarely revisited large data
|
|
47
|
+
const { data: report } = useQuery({
|
|
48
|
+
queryKey: ['detailed-report', reportId],
|
|
49
|
+
queryFn: () => fetchReport(reportId),
|
|
50
|
+
gcTime: 2 * 60 * 1000, // 2 minutes - large payload, viewed once
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// Sensible default with query-specific overrides
|
|
54
|
+
const queryClient = new QueryClient({
|
|
55
|
+
defaultOptions: {
|
|
56
|
+
queries: {
|
|
57
|
+
gcTime: 10 * 60 * 1000, // 10 minutes default
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Understanding gcTime vs staleTime
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Query Mount → Data Fresh (staleTime) → Data Stale → Query Unmount → gcTime countdown → Garbage Collected
|
|
67
|
+
|
|
68
|
+
Timeline example (staleTime: 1min, gcTime: 5min):
|
|
69
|
+
0:00 - Query mounts, fetches data
|
|
70
|
+
0:00-1:00 - Data is fresh (no background refetch)
|
|
71
|
+
1:00+ - Data is stale (background refetch on new mount)
|
|
72
|
+
5:00 - User navigates away, query unmounts
|
|
73
|
+
5:00-10:00 - Data in cache but inactive (gcTime countdown)
|
|
74
|
+
10:00 - Data garbage collected (next mount = full loading state)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Recommended gcTime Values
|
|
78
|
+
|
|
79
|
+
| Scenario | gcTime | Rationale |
|
|
80
|
+
|----------|--------|-----------|
|
|
81
|
+
| Frequently revisited routes | 15 - 30min | Instant navigation |
|
|
82
|
+
| Detail pages (viewed once) | 2 - 5min | Memory efficient |
|
|
83
|
+
| Large payloads | 1 - 2min | Prevent memory bloat |
|
|
84
|
+
| Critical user data | 30min+ | Offline-like experience |
|
|
85
|
+
| SSR hydration | >= 2s | Prevent hydration issues |
|
|
86
|
+
|
|
87
|
+
## Context
|
|
88
|
+
|
|
89
|
+
- gcTime countdown starts when ALL query observers unmount
|
|
90
|
+
- Remounting before gcTime expires returns cached data instantly
|
|
91
|
+
- Setting gcTime < staleTime is rarely useful
|
|
92
|
+
- For SSR, avoid gcTime: 0 (use minimum 2000ms to allow hydration)
|
|
93
|
+
- Monitor memory usage in long-running applications
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# cache-invalidation: Use Targeted Invalidation Over Broad Patterns
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
Query invalidation marks cached data as stale, triggering background refetches. Use targeted invalidation to refresh only affected data. Overly broad invalidation causes unnecessary network requests; too narrow invalidation leaves stale data.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Invalidating everything after a single todo update
|
|
13
|
+
const mutation = useMutation({
|
|
14
|
+
mutationFn: updateTodo,
|
|
15
|
+
onSuccess: () => {
|
|
16
|
+
queryClient.invalidateQueries() // Invalidates ENTIRE cache
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Invalidating too broadly
|
|
21
|
+
const mutation = useMutation({
|
|
22
|
+
mutationFn: updateTodoStatus,
|
|
23
|
+
onSuccess: () => {
|
|
24
|
+
// Invalidates all todos including unrelated lists
|
|
25
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Missing invalidation of related queries
|
|
30
|
+
const mutation = useMutation({
|
|
31
|
+
mutationFn: addComment,
|
|
32
|
+
onSuccess: () => {
|
|
33
|
+
// Only invalidates comment list, misses comment count
|
|
34
|
+
queryClient.invalidateQueries({ queryKey: ['comments', postId] })
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Good Example
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
// Targeted invalidation with exact matching
|
|
43
|
+
const mutation = useMutation({
|
|
44
|
+
mutationFn: updateTodo,
|
|
45
|
+
onSuccess: (data, variables) => {
|
|
46
|
+
// Invalidate specific todo and related queries
|
|
47
|
+
queryClient.invalidateQueries({ queryKey: ['todos', variables.id] })
|
|
48
|
+
// Also invalidate lists that might contain this todo
|
|
49
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 'list'] })
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// Use exact: true when you only want one specific query
|
|
54
|
+
const mutation = useMutation({
|
|
55
|
+
mutationFn: updateUserProfile,
|
|
56
|
+
onSuccess: () => {
|
|
57
|
+
queryClient.invalidateQueries({
|
|
58
|
+
queryKey: ['user', 'profile'],
|
|
59
|
+
exact: true, // Only this exact key, not ['user', 'profile', 'settings']
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Invalidate multiple related queries
|
|
65
|
+
const mutation = useMutation({
|
|
66
|
+
mutationFn: addComment,
|
|
67
|
+
onSuccess: (data, { postId }) => {
|
|
68
|
+
// Invalidate all comment-related queries for this post
|
|
69
|
+
queryClient.invalidateQueries({ queryKey: ['posts', postId, 'comments'] })
|
|
70
|
+
queryClient.invalidateQueries({ queryKey: ['posts', postId, 'comment-count'] })
|
|
71
|
+
// Optionally invalidate the post itself if it shows comment count
|
|
72
|
+
queryClient.invalidateQueries({ queryKey: ['posts', postId] })
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Predicate-based invalidation for complex scenarios
|
|
77
|
+
queryClient.invalidateQueries({
|
|
78
|
+
predicate: (query) =>
|
|
79
|
+
query.queryKey[0] === 'todos' &&
|
|
80
|
+
query.state.data?.userId === currentUserId,
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Invalidation Patterns
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
// Prefix matching (default) - invalidates all matching prefixes
|
|
88
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
89
|
+
// Matches: ['todos'], ['todos', 1], ['todos', { status: 'done' }]
|
|
90
|
+
|
|
91
|
+
// Exact matching - only the exact key
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: ['todos'], exact: true })
|
|
93
|
+
// Matches: ['todos'] only
|
|
94
|
+
|
|
95
|
+
// Predicate matching - custom logic
|
|
96
|
+
queryClient.invalidateQueries({
|
|
97
|
+
predicate: (query) => query.queryKey.includes('user-generated'),
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
// Refetch type control
|
|
101
|
+
queryClient.invalidateQueries({
|
|
102
|
+
queryKey: ['todos'],
|
|
103
|
+
refetchType: 'active', // Only refetch active queries (default)
|
|
104
|
+
// refetchType: 'inactive' - Only inactive
|
|
105
|
+
// refetchType: 'all' - Both
|
|
106
|
+
// refetchType: 'none' - Mark stale but don't refetch
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Context
|
|
111
|
+
|
|
112
|
+
- Invalidation only marks queries as stale; refetch happens when query is used
|
|
113
|
+
- `refetchType: 'active'` (default) only refetches queries with active observers
|
|
114
|
+
- Use hierarchical query keys to enable precise invalidation
|
|
115
|
+
- Consider `setQueryData` for optimistic updates instead of invalidation
|
|
116
|
+
- Always test invalidation patterns to ensure all affected queries are refreshed
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# cache-placeholder-vs-initial: Understand Placeholder vs Initial Data
|
|
2
|
+
|
|
3
|
+
## Priority: MEDIUM
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
`placeholderData` and `initialData` both provide data before the fetch completes, but behave differently. `initialData` is treated as real cached data, while `placeholderData` is temporary and doesn't persist to cache. Choose based on whether your fallback data should be cached.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Using initialData when you don't want it cached
|
|
13
|
+
function PostPreview({ postId, previewData }: Props) {
|
|
14
|
+
const { data } = useQuery({
|
|
15
|
+
queryKey: ['posts', postId],
|
|
16
|
+
queryFn: () => fetchPost(postId),
|
|
17
|
+
initialData: previewData, // Wrong: this becomes cached "truth"
|
|
18
|
+
// If previewData is incomplete, it pollutes the cache
|
|
19
|
+
// staleTime applies to this data as if it were fetched
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Using placeholderData when you want persistence
|
|
24
|
+
function UserProfile({ userId }: Props) {
|
|
25
|
+
const { data } = useQuery({
|
|
26
|
+
queryKey: ['users', userId],
|
|
27
|
+
queryFn: () => fetchUser(userId),
|
|
28
|
+
placeholderData: cachedUserFromList, // Wrong: won't persist
|
|
29
|
+
// User navigates away and back - placeholder shown again
|
|
30
|
+
// No cache entry created until fetch completes
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Good Example: placeholderData for Temporary Display
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
// Show list data while fetching detail
|
|
39
|
+
function PostDetail({ postId }: { postId: string }) {
|
|
40
|
+
const queryClient = useQueryClient()
|
|
41
|
+
|
|
42
|
+
const { data, isPlaceholderData } = useQuery({
|
|
43
|
+
queryKey: ['posts', postId],
|
|
44
|
+
queryFn: () => fetchPost(postId),
|
|
45
|
+
placeholderData: () => {
|
|
46
|
+
// Use partial data from list cache as placeholder
|
|
47
|
+
const posts = queryClient.getQueryData<Post[]>(['posts'])
|
|
48
|
+
return posts?.find(p => p.id === postId)
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<article className={isPlaceholderData ? 'opacity-50' : ''}>
|
|
54
|
+
<h1>{data?.title}</h1>
|
|
55
|
+
{isPlaceholderData ? (
|
|
56
|
+
<p>Loading full content...</p>
|
|
57
|
+
) : (
|
|
58
|
+
<div>{data?.content}</div>
|
|
59
|
+
)}
|
|
60
|
+
</article>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Good Example: initialData for Known Good Data
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
// SSR: Data fetched on server should be initial
|
|
69
|
+
function PostPage({ serverData }: { serverData: Post }) {
|
|
70
|
+
const { data } = useQuery({
|
|
71
|
+
queryKey: ['posts', serverData.id],
|
|
72
|
+
queryFn: () => fetchPost(serverData.id),
|
|
73
|
+
initialData: serverData,
|
|
74
|
+
// Specify when this data was fetched for proper stale calculation
|
|
75
|
+
initialDataUpdatedAt: serverData.fetchedAt,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return <PostContent post={data} />
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Pre-seeding cache with complete data
|
|
82
|
+
function App() {
|
|
83
|
+
const queryClient = useQueryClient()
|
|
84
|
+
|
|
85
|
+
// If you have complete, authoritative data
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
queryClient.setQueryData(['config'], completeConfigData)
|
|
88
|
+
}, [])
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Good Example: keepPreviousData Pattern
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
// Keep showing old data while fetching new (pagination, filters)
|
|
96
|
+
function ProductList({ page }: { page: number }) {
|
|
97
|
+
const { data, isPlaceholderData } = useQuery({
|
|
98
|
+
queryKey: ['products', page],
|
|
99
|
+
queryFn: () => fetchProducts(page),
|
|
100
|
+
placeholderData: keepPreviousData, // Built-in helper
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className={isPlaceholderData ? 'opacity-70' : ''}>
|
|
105
|
+
{data?.map(product => (
|
|
106
|
+
<ProductCard key={product.id} product={product} />
|
|
107
|
+
))}
|
|
108
|
+
{isPlaceholderData && <LoadingOverlay />}
|
|
109
|
+
</div>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Comparison Table
|
|
115
|
+
|
|
116
|
+
| Behavior | `initialData` | `placeholderData` |
|
|
117
|
+
|----------|---------------|-------------------|
|
|
118
|
+
| Persisted to cache | Yes | No |
|
|
119
|
+
| `staleTime` applies | Yes | No (always fetches) |
|
|
120
|
+
| `isPlaceholderData` | `false` | `true` |
|
|
121
|
+
| Shown to other components | Yes (cached) | No |
|
|
122
|
+
| Use case | SSR, complete known data | Preview, previous page |
|
|
123
|
+
| Affects `dataUpdatedAt` | Yes (use `initialDataUpdatedAt`) | No |
|
|
124
|
+
|
|
125
|
+
## Good Example: Combining Both
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
function PostDetail({ postId, ssrData }: Props) {
|
|
129
|
+
const queryClient = useQueryClient()
|
|
130
|
+
|
|
131
|
+
const { data } = useQuery({
|
|
132
|
+
queryKey: ['posts', postId],
|
|
133
|
+
queryFn: () => fetchPost(postId),
|
|
134
|
+
|
|
135
|
+
// If we have SSR data, use as initial (cached)
|
|
136
|
+
initialData: ssrData,
|
|
137
|
+
initialDataUpdatedAt: ssrData?.fetchedAt,
|
|
138
|
+
|
|
139
|
+
// If no SSR data, try to use list preview as placeholder
|
|
140
|
+
placeholderData: () => {
|
|
141
|
+
if (ssrData) return undefined // Already have initial
|
|
142
|
+
const posts = queryClient.getQueryData<Post[]>(['posts'])
|
|
143
|
+
return posts?.find(p => p.id === postId)
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Context
|
|
150
|
+
|
|
151
|
+
- `placeholderData` can be a value or function (lazy evaluation)
|
|
152
|
+
- `initialData` affects cache immediately on query creation
|
|
153
|
+
- Use `initialDataUpdatedAt` with `initialData` for proper stale calculations
|
|
154
|
+
- `keepPreviousData` is a built-in placeholder strategy
|
|
155
|
+
- Check `isPlaceholderData` to show loading indicators
|
|
156
|
+
- `placeholderData` is ideal for "instant" UI while fetching
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# cache-stale-time: Set Appropriate staleTime Based on Data Volatility
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
`staleTime` determines how long data is considered fresh. The default is 0ms, meaning data is immediately stale and will refetch on every new query mount. Set appropriate staleTime based on how often your data actually changes to reduce unnecessary network requests.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Default staleTime of 0 - refetches on every component mount
|
|
13
|
+
const { data } = useQuery({
|
|
14
|
+
queryKey: ['user-profile', userId],
|
|
15
|
+
queryFn: () => fetchUserProfile(userId),
|
|
16
|
+
// No staleTime set - always considered stale
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// User profile probably doesn't change every second
|
|
20
|
+
// This causes unnecessary API calls on navigation
|
|
21
|
+
|
|
22
|
+
// Setting same staleTime everywhere regardless of data type
|
|
23
|
+
const queryClient = new QueryClient({
|
|
24
|
+
defaultOptions: {
|
|
25
|
+
queries: {
|
|
26
|
+
staleTime: 60 * 1000, // 1 minute for everything - too simple
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Good Example
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
// Match staleTime to data volatility
|
|
36
|
+
const { data: profile } = useQuery({
|
|
37
|
+
queryKey: ['user-profile', userId],
|
|
38
|
+
queryFn: () => fetchUserProfile(userId),
|
|
39
|
+
staleTime: 5 * 60 * 1000, // 5 minutes - profile rarely changes
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const { data: notifications } = useQuery({
|
|
43
|
+
queryKey: ['notifications'],
|
|
44
|
+
queryFn: fetchNotifications,
|
|
45
|
+
staleTime: 30 * 1000, // 30 seconds - changes more frequently
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const { data: stockPrice } = useQuery({
|
|
49
|
+
queryKey: ['stock', symbol],
|
|
50
|
+
queryFn: () => fetchStockPrice(symbol),
|
|
51
|
+
staleTime: 0, // Real-time data - always refetch
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Set sensible defaults, override per-query
|
|
55
|
+
const queryClient = new QueryClient({
|
|
56
|
+
defaultOptions: {
|
|
57
|
+
queries: {
|
|
58
|
+
staleTime: 60 * 1000, // 1 minute default
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Recommended staleTime Values
|
|
65
|
+
|
|
66
|
+
| Data Type | staleTime | Rationale |
|
|
67
|
+
|-----------|-----------|-----------|
|
|
68
|
+
| Real-time (stocks, live feeds) | 0 | Must always be current |
|
|
69
|
+
| Frequently changing (notifications) | 30s - 1min | Balance freshness and requests |
|
|
70
|
+
| User-generated content | 1 - 5min | Changes on user action |
|
|
71
|
+
| Reference data (categories, config) | 10 - 30min | Rarely changes |
|
|
72
|
+
| Static content | Infinity | Never changes |
|
|
73
|
+
|
|
74
|
+
## Context
|
|
75
|
+
|
|
76
|
+
- `staleTime: 0` (default) triggers background refetch on every mount
|
|
77
|
+
- `staleTime: Infinity` never considers data stale (manual invalidation only)
|
|
78
|
+
- Stale data is still returned instantly - refetch happens in background
|
|
79
|
+
- For SSR, set higher staleTime to avoid immediate client refetch
|
|
80
|
+
- Consider using `queryOptions` factory to centralize staleTime per data type
|