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,179 @@
|
|
|
1
|
+
# network-mode: Configure Network Mode for Offline Support
|
|
2
|
+
|
|
3
|
+
## Priority: LOW
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
TanStack Query's `networkMode` controls how queries and mutations behave when there's no network connection. Configure it based on your app's offline requirements: always fetch, pause when offline, or work entirely offline.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Not considering offline behavior
|
|
13
|
+
const { data } = useQuery({
|
|
14
|
+
queryKey: ['todos'],
|
|
15
|
+
queryFn: fetchTodos,
|
|
16
|
+
// Default networkMode: 'online'
|
|
17
|
+
// Query pauses with no feedback when offline
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// User goes offline, sees stale data with no indication
|
|
21
|
+
// Mutations silently queue with no UI feedback
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Good Example: Default Online Mode with Offline UI
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
// Show clear offline state to users
|
|
28
|
+
function TodoList() {
|
|
29
|
+
const { data, fetchStatus, status } = useQuery({
|
|
30
|
+
queryKey: ['todos'],
|
|
31
|
+
queryFn: fetchTodos,
|
|
32
|
+
networkMode: 'online', // Default - pauses when offline
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// fetchStatus: 'fetching' | 'paused' | 'idle'
|
|
36
|
+
// 'paused' means waiting for network
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
{fetchStatus === 'paused' && (
|
|
41
|
+
<Banner>You're offline. Showing cached data.</Banner>
|
|
42
|
+
)}
|
|
43
|
+
<TodoItems todos={data} />
|
|
44
|
+
</div>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Good Example: Always Mode for Offline-First
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// App works offline with local data
|
|
53
|
+
const { data, error } = useQuery({
|
|
54
|
+
queryKey: ['todos'],
|
|
55
|
+
queryFn: async () => {
|
|
56
|
+
// Try network first
|
|
57
|
+
try {
|
|
58
|
+
const todos = await fetchTodosFromServer()
|
|
59
|
+
await saveToLocalDB(todos) // Sync to local
|
|
60
|
+
return todos
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// Fall back to local data
|
|
63
|
+
return getFromLocalDB()
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
networkMode: 'always', // Always runs queryFn, even offline
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
// Or set globally
|
|
70
|
+
const queryClient = new QueryClient({
|
|
71
|
+
defaultOptions: {
|
|
72
|
+
queries: {
|
|
73
|
+
networkMode: 'always',
|
|
74
|
+
},
|
|
75
|
+
mutations: {
|
|
76
|
+
networkMode: 'always',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Good Example: Offline-First Mode
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
// Only fetch when online, but don't fail when offline
|
|
86
|
+
const { data } = useQuery({
|
|
87
|
+
queryKey: ['user-preferences'],
|
|
88
|
+
queryFn: fetchPreferences,
|
|
89
|
+
networkMode: 'offlineFirst',
|
|
90
|
+
// Runs queryFn once, then waits for network if it fails
|
|
91
|
+
// Good for: data that's useful to attempt offline
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Good Example: Mutation Offline Queue
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
function TodoApp() {
|
|
99
|
+
const queryClient = useQueryClient()
|
|
100
|
+
|
|
101
|
+
const addTodo = useMutation({
|
|
102
|
+
mutationFn: createTodo,
|
|
103
|
+
networkMode: 'online', // Pauses when offline
|
|
104
|
+
onMutate: async (newTodo) => {
|
|
105
|
+
// Optimistic update works offline
|
|
106
|
+
await queryClient.cancelQueries({ queryKey: ['todos'] })
|
|
107
|
+
const previous = queryClient.getQueryData(['todos'])
|
|
108
|
+
queryClient.setQueryData(['todos'], (old: Todo[]) => [...old, newTodo])
|
|
109
|
+
return { previous }
|
|
110
|
+
},
|
|
111
|
+
onError: (err, newTodo, context) => {
|
|
112
|
+
queryClient.setQueryData(['todos'], context?.previous)
|
|
113
|
+
},
|
|
114
|
+
onSettled: () => {
|
|
115
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Track paused mutations
|
|
120
|
+
const pendingMutations = useMutationState({
|
|
121
|
+
filters: { status: 'pending' },
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const pausedMutations = pendingMutations.filter(
|
|
125
|
+
m => m.state.isPaused
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div>
|
|
130
|
+
{pausedMutations.length > 0 && (
|
|
131
|
+
<Banner>
|
|
132
|
+
{pausedMutations.length} changes waiting to sync
|
|
133
|
+
</Banner>
|
|
134
|
+
)}
|
|
135
|
+
<TodoList />
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Network Mode Comparison
|
|
142
|
+
|
|
143
|
+
| Mode | Behavior | Use Case |
|
|
144
|
+
|------|----------|----------|
|
|
145
|
+
| `'online'` (default) | Pauses when offline, resumes when online | Most apps, show offline state |
|
|
146
|
+
| `'always'` | Always runs queryFn regardless of network | Offline-first apps, local-only data |
|
|
147
|
+
| `'offlineFirst'` | Tries once, then waits for network if fails | Best-effort offline |
|
|
148
|
+
|
|
149
|
+
## Good Example: Online Status Detection
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { onlineManager } from '@tanstack/react-query'
|
|
153
|
+
|
|
154
|
+
// React to online/offline changes
|
|
155
|
+
function NetworkStatus() {
|
|
156
|
+
const isOnline = useSyncExternalStore(
|
|
157
|
+
onlineManager.subscribe,
|
|
158
|
+
() => onlineManager.isOnline(),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div className={isOnline ? 'online' : 'offline'}>
|
|
163
|
+
{isOnline ? 'Connected' : 'Offline'}
|
|
164
|
+
</div>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Manually override online detection (for testing)
|
|
169
|
+
onlineManager.setOnline(false)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Context
|
|
173
|
+
|
|
174
|
+
- Default `'online'` mode is best for most apps
|
|
175
|
+
- `fetchStatus: 'paused'` indicates waiting for network
|
|
176
|
+
- Mutations queue automatically and retry when back online
|
|
177
|
+
- Use `onlineManager` to detect and control online state
|
|
178
|
+
- Combine with optimistic updates for seamless offline UX
|
|
179
|
+
- Consider service workers for true offline support
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# parallel-use-queries: Use useQueries for Dynamic Parallel Queries
|
|
2
|
+
|
|
3
|
+
## Priority: MEDIUM
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
When you need to fetch multiple queries in parallel where the number or identity of queries is dynamic (e.g., fetching details for a list of IDs), use `useQueries`. It handles parallel execution and returns an array of query results.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Sequential fetching with useEffect - waterfall
|
|
13
|
+
function UserProfiles({ userIds }: { userIds: string[] }) {
|
|
14
|
+
const [users, setUsers] = useState<User[]>([])
|
|
15
|
+
const [loading, setLoading] = useState(true)
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
async function fetchAll() {
|
|
19
|
+
const results = []
|
|
20
|
+
for (const id of userIds) {
|
|
21
|
+
const user = await fetchUser(id) // Sequential!
|
|
22
|
+
results.push(user)
|
|
23
|
+
}
|
|
24
|
+
setUsers(results)
|
|
25
|
+
setLoading(false)
|
|
26
|
+
}
|
|
27
|
+
fetchAll()
|
|
28
|
+
}, [userIds])
|
|
29
|
+
|
|
30
|
+
// N requests run one after another
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Multiple useQuery calls - breaks rules of hooks
|
|
34
|
+
function UserProfiles({ userIds }: { userIds: string[] }) {
|
|
35
|
+
// Can't call hooks in a loop!
|
|
36
|
+
const queries = userIds.map(id => useQuery({
|
|
37
|
+
queryKey: ['user', id],
|
|
38
|
+
queryFn: () => fetchUser(id),
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Good Example
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { useQueries } from '@tanstack/react-query'
|
|
47
|
+
|
|
48
|
+
function UserProfiles({ userIds }: { userIds: string[] }) {
|
|
49
|
+
const userQueries = useQueries({
|
|
50
|
+
queries: userIds.map(id => ({
|
|
51
|
+
queryKey: ['users', id],
|
|
52
|
+
queryFn: () => fetchUser(id),
|
|
53
|
+
staleTime: 5 * 60 * 1000,
|
|
54
|
+
})),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const isLoading = userQueries.some(q => q.isLoading)
|
|
58
|
+
const isError = userQueries.some(q => q.isError)
|
|
59
|
+
const users = userQueries.map(q => q.data).filter(Boolean)
|
|
60
|
+
|
|
61
|
+
if (isLoading) return <Loading />
|
|
62
|
+
if (isError) return <Error />
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ul>
|
|
66
|
+
{users.map(user => (
|
|
67
|
+
<li key={user.id}>{user.name}</li>
|
|
68
|
+
))}
|
|
69
|
+
</ul>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Good Example: With Combine Option
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
function UserProfiles({ userIds }: { userIds: string[] }) {
|
|
78
|
+
const { data: users, isPending } = useQueries({
|
|
79
|
+
queries: userIds.map(id => ({
|
|
80
|
+
queryKey: ['users', id],
|
|
81
|
+
queryFn: () => fetchUser(id),
|
|
82
|
+
})),
|
|
83
|
+
// Combine results into single value
|
|
84
|
+
combine: (results) => ({
|
|
85
|
+
data: results.map(r => r.data).filter(Boolean),
|
|
86
|
+
isPending: results.some(r => r.isPending),
|
|
87
|
+
isError: results.some(r => r.isError),
|
|
88
|
+
}),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
if (isPending) return <Loading />
|
|
92
|
+
|
|
93
|
+
return <UserList users={users} />
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Good Example: Dependent Parallel Queries
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
function PostsWithAuthors({ postIds }: { postIds: string[] }) {
|
|
101
|
+
// First: fetch all posts in parallel
|
|
102
|
+
const postQueries = useQueries({
|
|
103
|
+
queries: postIds.map(id => ({
|
|
104
|
+
queryKey: ['posts', id],
|
|
105
|
+
queryFn: () => fetchPost(id),
|
|
106
|
+
})),
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const posts = postQueries.map(q => q.data).filter(Boolean)
|
|
110
|
+
const authorIds = [...new Set(posts.map(p => p.authorId))]
|
|
111
|
+
|
|
112
|
+
// Then: fetch all unique authors in parallel
|
|
113
|
+
const authorQueries = useQueries({
|
|
114
|
+
queries: authorIds.map(id => ({
|
|
115
|
+
queryKey: ['users', id],
|
|
116
|
+
queryFn: () => fetchUser(id),
|
|
117
|
+
enabled: posts.length > 0, // Wait for posts
|
|
118
|
+
})),
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Combine data...
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Good Example: With Suspense
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { useSuspenseQueries } from '@tanstack/react-query'
|
|
129
|
+
|
|
130
|
+
function UserProfiles({ userIds }: { userIds: string[] }) {
|
|
131
|
+
const userQueries = useSuspenseQueries({
|
|
132
|
+
queries: userIds.map(id => ({
|
|
133
|
+
queryKey: ['users', id],
|
|
134
|
+
queryFn: () => fetchUser(id),
|
|
135
|
+
})),
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
// All data guaranteed - no loading states needed
|
|
139
|
+
const users = userQueries.map(q => q.data)
|
|
140
|
+
|
|
141
|
+
return <UserList users={users} />
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Context
|
|
146
|
+
|
|
147
|
+
- Queries run in parallel, not sequentially
|
|
148
|
+
- Each query is cached independently
|
|
149
|
+
- Use `combine` to transform results array into single value
|
|
150
|
+
- Empty queries array is valid (returns empty results)
|
|
151
|
+
- Pairs well with `useSuspenseQueries` for guaranteed data
|
|
152
|
+
- Individual query options (staleTime, etc.) apply per-query
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# perf-select-transform: Use Select to Transform and Filter Data
|
|
2
|
+
|
|
3
|
+
## Priority: LOW
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
The `select` option transforms query data before it reaches your component. Use it for filtering, sorting, or deriving data. Benefits include memoization (re-runs only when data changes) and reduced component re-renders.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Transforming in component - runs on every render
|
|
13
|
+
function CompletedTodos() {
|
|
14
|
+
const { data: todos } = useQuery({
|
|
15
|
+
queryKey: ['todos'],
|
|
16
|
+
queryFn: fetchTodos,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// This filtering runs on every render
|
|
20
|
+
const completedTodos = todos?.filter(todo => todo.completed) ?? []
|
|
21
|
+
const sortedTodos = [...completedTodos].sort((a, b) =>
|
|
22
|
+
new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime()
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
return <TodoList todos={sortedTodos} />
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Good Example
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// Using select - runs only when data changes
|
|
33
|
+
function CompletedTodos() {
|
|
34
|
+
const { data: completedTodos } = useQuery({
|
|
35
|
+
queryKey: ['todos'],
|
|
36
|
+
queryFn: fetchTodos,
|
|
37
|
+
select: (todos) =>
|
|
38
|
+
todos
|
|
39
|
+
.filter(todo => todo.completed)
|
|
40
|
+
.sort((a, b) =>
|
|
41
|
+
new Date(b.completedAt).getTime() - new Date(a.completedAt).getTime()
|
|
42
|
+
),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return <TodoList todos={completedTodos ?? []} />
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Good Example: Selecting Specific Fields
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// Derive computed values
|
|
53
|
+
function TodoStats() {
|
|
54
|
+
const { data: stats } = useQuery({
|
|
55
|
+
queryKey: ['todos'],
|
|
56
|
+
queryFn: fetchTodos,
|
|
57
|
+
select: (todos) => ({
|
|
58
|
+
total: todos.length,
|
|
59
|
+
completed: todos.filter(t => t.completed).length,
|
|
60
|
+
pending: todos.filter(t => !t.completed).length,
|
|
61
|
+
completionRate: todos.length
|
|
62
|
+
? (todos.filter(t => t.completed).length / todos.length) * 100
|
|
63
|
+
: 0,
|
|
64
|
+
}),
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<span>{stats?.completed} / {stats?.total} completed</span>
|
|
70
|
+
<span>({stats?.completionRate.toFixed(1)}%)</span>
|
|
71
|
+
</div>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Good Example: Stable Select with useCallback
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
// When select depends on external values, stabilize with useCallback
|
|
80
|
+
function FilteredTodos({ status }: { status: 'all' | 'active' | 'completed' }) {
|
|
81
|
+
const selectTodos = useCallback(
|
|
82
|
+
(todos: Todo[]) => {
|
|
83
|
+
switch (status) {
|
|
84
|
+
case 'active':
|
|
85
|
+
return todos.filter(t => !t.completed)
|
|
86
|
+
case 'completed':
|
|
87
|
+
return todos.filter(t => t.completed)
|
|
88
|
+
default:
|
|
89
|
+
return todos
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
[status]
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
const { data: filteredTodos } = useQuery({
|
|
96
|
+
queryKey: ['todos'],
|
|
97
|
+
queryFn: fetchTodos,
|
|
98
|
+
select: selectTodos,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
return <TodoList todos={filteredTodos ?? []} />
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Good Example: Picking Single Item from List
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
// Select single item from cached list
|
|
109
|
+
function useTodoById(id: number) {
|
|
110
|
+
return useQuery({
|
|
111
|
+
queryKey: ['todos'],
|
|
112
|
+
queryFn: fetchTodos,
|
|
113
|
+
select: (todos) => todos.find(todo => todo.id === id),
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Usage - shares cache with list query
|
|
118
|
+
function TodoDetail({ id }: { id: number }) {
|
|
119
|
+
const { data: todo } = useTodoById(id)
|
|
120
|
+
|
|
121
|
+
if (!todo) return <div>Todo not found</div>
|
|
122
|
+
return <div>{todo.title}</div>
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## When to Use Select
|
|
127
|
+
|
|
128
|
+
| Scenario | Use Select? |
|
|
129
|
+
|----------|-------------|
|
|
130
|
+
| Filtering list data | Yes |
|
|
131
|
+
| Sorting data | Yes |
|
|
132
|
+
| Computing derived values | Yes |
|
|
133
|
+
| Picking single item from list | Yes |
|
|
134
|
+
| Heavy transformations | Yes (memoized) |
|
|
135
|
+
| Simple data pass-through | No |
|
|
136
|
+
| Transformation needs external state | Yes, with useCallback |
|
|
137
|
+
|
|
138
|
+
## Context
|
|
139
|
+
|
|
140
|
+
- `select` leverages structural sharing - only re-runs when data actually changes
|
|
141
|
+
- Original query data stays cached; transformation applies to consumer
|
|
142
|
+
- Multiple components can use different `select` on the same query
|
|
143
|
+
- Avoid unstable function references - use `useCallback` when needed
|
|
144
|
+
- For complex transformations, consider useMemo in component instead if readability suffers
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# persist-queries: Configure Query Persistence for Offline Support
|
|
2
|
+
|
|
3
|
+
## Priority: LOW
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
TanStack Query can persist the cache to storage (localStorage, IndexedDB, AsyncStorage) and restore it on app load. This enables offline support and faster startup by eliminating initial loading states.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// No persistence - always starts fresh
|
|
13
|
+
const queryClient = new QueryClient()
|
|
14
|
+
|
|
15
|
+
function App() {
|
|
16
|
+
return (
|
|
17
|
+
<QueryClientProvider client={queryClient}>
|
|
18
|
+
<MyApp />
|
|
19
|
+
</QueryClientProvider>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// User refreshes page:
|
|
24
|
+
// 1. Empty cache
|
|
25
|
+
// 2. Loading spinners everywhere
|
|
26
|
+
// 3. Refetch all data
|
|
27
|
+
// Poor offline experience
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Good Example: Basic Persistence with localStorage
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { QueryClient } from '@tanstack/react-query'
|
|
34
|
+
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
|
|
35
|
+
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
|
|
36
|
+
|
|
37
|
+
const queryClient = new QueryClient({
|
|
38
|
+
defaultOptions: {
|
|
39
|
+
queries: {
|
|
40
|
+
gcTime: 1000 * 60 * 60 * 24, // 24 hours - keep cache longer for persistence
|
|
41
|
+
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const persister = createSyncStoragePersister({
|
|
47
|
+
storage: window.localStorage,
|
|
48
|
+
key: 'REACT_QUERY_CACHE',
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
function App() {
|
|
52
|
+
return (
|
|
53
|
+
<PersistQueryClientProvider
|
|
54
|
+
client={queryClient}
|
|
55
|
+
persistOptions={{
|
|
56
|
+
persister,
|
|
57
|
+
maxAge: 1000 * 60 * 60 * 24, // 24 hours max
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
<MyApp />
|
|
61
|
+
</PersistQueryClientProvider>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Good Example: Async Persistence with IndexedDB
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
|
|
70
|
+
import { get, set, del } from 'idb-keyval'
|
|
71
|
+
|
|
72
|
+
const persister = createAsyncStoragePersister({
|
|
73
|
+
storage: {
|
|
74
|
+
getItem: async (key) => await get(key),
|
|
75
|
+
setItem: async (key, value) => await set(key, value),
|
|
76
|
+
removeItem: async (key) => await del(key),
|
|
77
|
+
},
|
|
78
|
+
key: 'REACT_QUERY_CACHE',
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
function App() {
|
|
82
|
+
return (
|
|
83
|
+
<PersistQueryClientProvider
|
|
84
|
+
client={queryClient}
|
|
85
|
+
persistOptions={{
|
|
86
|
+
persister,
|
|
87
|
+
maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days
|
|
88
|
+
buster: APP_VERSION, // Bust cache on app updates
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<MyApp />
|
|
92
|
+
</PersistQueryClientProvider>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Good Example: Selective Persistence
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { persistQueryClient } from '@tanstack/react-query-persist-client'
|
|
101
|
+
|
|
102
|
+
const queryClient = new QueryClient({
|
|
103
|
+
defaultOptions: {
|
|
104
|
+
queries: {
|
|
105
|
+
gcTime: 1000 * 60 * 60 * 24,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// Only persist certain queries
|
|
111
|
+
persistQueryClient({
|
|
112
|
+
queryClient,
|
|
113
|
+
persister,
|
|
114
|
+
dehydrateOptions: {
|
|
115
|
+
shouldDehydrateQuery: (query) => {
|
|
116
|
+
// Don't persist user-specific sensitive data
|
|
117
|
+
if (query.queryKey[0] === 'user-session') return false
|
|
118
|
+
// Don't persist real-time data
|
|
119
|
+
if (query.queryKey[0] === 'notifications') return false
|
|
120
|
+
// Don't persist failed queries
|
|
121
|
+
if (query.state.status !== 'success') return false
|
|
122
|
+
// Persist everything else
|
|
123
|
+
return true
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Good Example: React Native with AsyncStorage
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
133
|
+
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
|
|
134
|
+
|
|
135
|
+
const persister = createAsyncStoragePersister({
|
|
136
|
+
storage: AsyncStorage,
|
|
137
|
+
key: 'app-query-cache',
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
// Usage is the same as web
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Good Example: Handling Restoration Loading
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
|
|
147
|
+
|
|
148
|
+
function App() {
|
|
149
|
+
return (
|
|
150
|
+
<PersistQueryClientProvider
|
|
151
|
+
client={queryClient}
|
|
152
|
+
persistOptions={{ persister }}
|
|
153
|
+
onSuccess={() => {
|
|
154
|
+
// Cache restored successfully
|
|
155
|
+
console.log('Cache restored')
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
{/* Show loading while restoring */}
|
|
159
|
+
<PersistQueryClientProvider.Consumer>
|
|
160
|
+
{({ isRestoring }) =>
|
|
161
|
+
isRestoring ? <SplashScreen /> : <MainApp />
|
|
162
|
+
}
|
|
163
|
+
</PersistQueryClientProvider.Consumer>
|
|
164
|
+
</PersistQueryClientProvider>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Or use the hook
|
|
169
|
+
function MainApp() {
|
|
170
|
+
const { isRestoring } = usePersistQueryClientRestore()
|
|
171
|
+
|
|
172
|
+
if (isRestoring) return <SplashScreen />
|
|
173
|
+
return <App />
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Persistence Configuration
|
|
178
|
+
|
|
179
|
+
| Option | Purpose |
|
|
180
|
+
|--------|---------|
|
|
181
|
+
| `maxAge` | Maximum cache age before considered invalid |
|
|
182
|
+
| `buster` | String to invalidate cache (use app version) |
|
|
183
|
+
| `dehydrateOptions.shouldDehydrateQuery` | Filter which queries to persist |
|
|
184
|
+
| `hydrateOptions.shouldHydrate` | Filter which queries to restore |
|
|
185
|
+
|
|
186
|
+
## Context
|
|
187
|
+
|
|
188
|
+
- Requires `@tanstack/react-query-persist-client` package
|
|
189
|
+
- Set `gcTime` higher than default (5 min) for persistence to be useful
|
|
190
|
+
- Use `buster` option to invalidate cache on app updates
|
|
191
|
+
- Don't persist sensitive data or real-time data
|
|
192
|
+
- IndexedDB is better than localStorage for large caches
|
|
193
|
+
- Restored data is still subject to staleTime checks
|
|
194
|
+
- Works well with `networkMode: 'offlineFirst'`
|