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
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
# Recharts Best Practices
|
|
2
|
+
|
|
3
|
+
Design, performance, and accessibility guidelines for building production-ready charts with Recharts.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [Performance Optimization](#performance-optimization)
|
|
8
|
+
2. [Responsive Design](#responsive-design)
|
|
9
|
+
3. [Accessibility](#accessibility)
|
|
10
|
+
4. [Data Patterns](#data-patterns)
|
|
11
|
+
5. [Visual Design](#visual-design)
|
|
12
|
+
6. [Testing and Debugging](#testing-and-debugging)
|
|
13
|
+
7. [Common Pitfalls](#common-pitfalls)
|
|
14
|
+
|
|
15
|
+
## Performance Optimization
|
|
16
|
+
|
|
17
|
+
### 1. Memoize Data and Props
|
|
18
|
+
|
|
19
|
+
Always use `useMemo` for data transformations and `useCallback` for event handlers:
|
|
20
|
+
|
|
21
|
+
```jsx
|
|
22
|
+
// GOOD: Stable data reference
|
|
23
|
+
const processedData = useMemo(() => {
|
|
24
|
+
return rawData.map(item => ({
|
|
25
|
+
...item,
|
|
26
|
+
total: item.revenue + item.expenses
|
|
27
|
+
}));
|
|
28
|
+
}, [rawData]);
|
|
29
|
+
|
|
30
|
+
// GOOD: Stable callback
|
|
31
|
+
const handleClick = useCallback((data) => {
|
|
32
|
+
console.log('Clicked:', data);
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
// GOOD: Stable dataKey function
|
|
36
|
+
const dataKeyFn = useCallback((entry) => entry.value * 100, []);
|
|
37
|
+
|
|
38
|
+
<LineChart data={processedData}>
|
|
39
|
+
<Line dataKey={dataKeyFn} onClick={handleClick} />
|
|
40
|
+
</LineChart>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Why this matters**: Recharts compares props by reference. New function references on each render trigger unnecessary recalculations.
|
|
44
|
+
|
|
45
|
+
### 2. Memoize Components
|
|
46
|
+
|
|
47
|
+
Wrap chart components with `React.memo` when they receive stable props:
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
const MemoizedChart = React.memo(({ data }) => (
|
|
51
|
+
<LineChart data={data}>
|
|
52
|
+
<XAxis dataKey="name" />
|
|
53
|
+
<YAxis />
|
|
54
|
+
<Line type="monotone" dataKey="value" />
|
|
55
|
+
</LineChart>
|
|
56
|
+
));
|
|
57
|
+
|
|
58
|
+
// Parent component
|
|
59
|
+
function Dashboard() {
|
|
60
|
+
const [data] = useState(initialData);
|
|
61
|
+
|
|
62
|
+
return <MemoizedChart data={data} />; // Won't re-render if data is stable
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Isolate Frequently Updating Components
|
|
67
|
+
|
|
68
|
+
Separate static and dynamic chart parts:
|
|
69
|
+
|
|
70
|
+
```jsx
|
|
71
|
+
function OptimizedChart() {
|
|
72
|
+
const [hoveredPoint, setHoveredPoint] = useState(null);
|
|
73
|
+
|
|
74
|
+
// Debounced hover handler
|
|
75
|
+
const handleMouseMove = useDebouncedCallback((e) => {
|
|
76
|
+
if (e && e.activePayload) {
|
|
77
|
+
setHoveredPoint(e.activePayload[0]);
|
|
78
|
+
}
|
|
79
|
+
}, 50);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<LineChart data={data} onMouseMove={handleMouseMove}>
|
|
83
|
+
{/* Static - rarely changes */}
|
|
84
|
+
<CartesianGrid strokeDasharray="3 3" />
|
|
85
|
+
<XAxis dataKey="name" />
|
|
86
|
+
<YAxis />
|
|
87
|
+
<Tooltip />
|
|
88
|
+
<Line type="monotone" dataKey="sales" stroke="#8884d8" />
|
|
89
|
+
|
|
90
|
+
{/* Dynamic - changes often */}
|
|
91
|
+
{hoveredPoint && (
|
|
92
|
+
<ReferenceLine
|
|
93
|
+
x={hoveredPoint.payload.name}
|
|
94
|
+
stroke="#ff7300"
|
|
95
|
+
strokeDasharray="3 3"
|
|
96
|
+
/>
|
|
97
|
+
)}
|
|
98
|
+
</LineChart>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 4. Reduce Data Points for Large Datasets
|
|
104
|
+
|
|
105
|
+
For datasets with thousands of points, aggregate or sample:
|
|
106
|
+
|
|
107
|
+
```jsx
|
|
108
|
+
import * as d3 from 'd3';
|
|
109
|
+
|
|
110
|
+
function OptimizedLargeChart({ rawData }) {
|
|
111
|
+
// Sample data if too large
|
|
112
|
+
const data = useMemo(() => {
|
|
113
|
+
if (rawData.length <= 500) return rawData;
|
|
114
|
+
|
|
115
|
+
// Use d3.bin for histogram or simple sampling
|
|
116
|
+
const step = Math.ceil(rawData.length / 500);
|
|
117
|
+
return rawData.filter((_, i) => i % step === 0);
|
|
118
|
+
}, [rawData]);
|
|
119
|
+
|
|
120
|
+
// Or use binning for distributions
|
|
121
|
+
const binnedData = useMemo(() => {
|
|
122
|
+
if (rawData.length <= 500) return rawData;
|
|
123
|
+
|
|
124
|
+
const bin = d3.bin()
|
|
125
|
+
.value(d => d.x)
|
|
126
|
+
.thresholds(50);
|
|
127
|
+
|
|
128
|
+
return bin(rawData).map(b => ({
|
|
129
|
+
x0: b.x0,
|
|
130
|
+
x1: b.x1,
|
|
131
|
+
count: b.length,
|
|
132
|
+
y: d3.mean(b, d => d.y)
|
|
133
|
+
}));
|
|
134
|
+
}, [rawData]);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<ScatterChart>
|
|
138
|
+
<Scatter data={binnedData} />
|
|
139
|
+
</ScatterChart>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 5. Disable Animations for Real-time Data
|
|
145
|
+
|
|
146
|
+
```jsx
|
|
147
|
+
function RealtimeChart() {
|
|
148
|
+
const [data, setData] = useState([]);
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
const interval = setInterval(() => {
|
|
152
|
+
setData(prev => [...prev.slice(-50), newPoint]);
|
|
153
|
+
}, 100);
|
|
154
|
+
return () => clearInterval(interval);
|
|
155
|
+
}, []);
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<LineChart data={data}>
|
|
159
|
+
<Line
|
|
160
|
+
type="monotone"
|
|
161
|
+
dataKey="value"
|
|
162
|
+
stroke="#8884d8"
|
|
163
|
+
isAnimationActive={false} // Critical for performance
|
|
164
|
+
dot={false} // Disable dots
|
|
165
|
+
/>
|
|
166
|
+
</LineChart>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 6. Optimize Tooltip Performance
|
|
172
|
+
|
|
173
|
+
```jsx
|
|
174
|
+
// BAD: New component reference every render
|
|
175
|
+
<Tooltip content={<CustomTooltip />} />
|
|
176
|
+
|
|
177
|
+
// GOOD: Stable component reference
|
|
178
|
+
const CustomTooltip = useMemo(() => {
|
|
179
|
+
return ({ active, payload }) => {
|
|
180
|
+
if (active && payload) {
|
|
181
|
+
return <div>{payload[0].value}</div>;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
};
|
|
185
|
+
}, []);
|
|
186
|
+
|
|
187
|
+
<Tooltip content={CustomTooltip} />
|
|
188
|
+
|
|
189
|
+
// OR use a separate component outside the render function
|
|
190
|
+
const StableTooltip = React.memo(({ active, payload }) => {
|
|
191
|
+
if (!active || !payload) return null;
|
|
192
|
+
return <div>{payload[0].value}</div>;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
<Tooltip content={<StableTooltip />} />
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 7. Virtualize Lists with Charts
|
|
199
|
+
|
|
200
|
+
When rendering many charts in a list:
|
|
201
|
+
|
|
202
|
+
```jsx
|
|
203
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
204
|
+
|
|
205
|
+
function ChartList({ datasets }) {
|
|
206
|
+
const parentRef = useRef();
|
|
207
|
+
|
|
208
|
+
const virtualizer = useVirtualizer({
|
|
209
|
+
count: datasets.length,
|
|
210
|
+
getScrollElement: () => parentRef.current,
|
|
211
|
+
estimateSize: () => 300,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<div ref={parentRef} style={{ height: '600px', overflow: 'auto' }}>
|
|
216
|
+
<div style={{ height: `${virtualizer.getTotalSize()}px`, position: 'relative' }}>
|
|
217
|
+
{virtualizer.getVirtualItems().map(virtualItem => (
|
|
218
|
+
<div
|
|
219
|
+
key={virtualItem.key}
|
|
220
|
+
style={{
|
|
221
|
+
position: 'absolute',
|
|
222
|
+
top: 0,
|
|
223
|
+
left: 0,
|
|
224
|
+
width: '100%',
|
|
225
|
+
height: `${virtualItem.size}px`,
|
|
226
|
+
transform: `translateY(${virtualItem.start}px)`,
|
|
227
|
+
}}
|
|
228
|
+
>
|
|
229
|
+
<ChartComponent data={datasets[virtualItem.index]} />
|
|
230
|
+
</div>
|
|
231
|
+
))}
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Responsive Design
|
|
239
|
+
|
|
240
|
+
### 1. Use the `responsive` prop (Recharts 3.3+, recommended)
|
|
241
|
+
|
|
242
|
+
The `responsive` prop makes charts automatically resize when their container dimensions change. Works with standard CSS sizing, flexbox, and CSS grid:
|
|
243
|
+
|
|
244
|
+
```jsx
|
|
245
|
+
// GOOD: Responsive with CSS sizing
|
|
246
|
+
<LineChart data={data} responsive style={{ width: '100%', maxWidth: 800, aspectRatio: '16/9' }}>
|
|
247
|
+
{/* ... */}
|
|
248
|
+
</LineChart>
|
|
249
|
+
|
|
250
|
+
// GOOD: Responsive with explicit dimensions
|
|
251
|
+
<LineChart data={data} width="100%" height={300} responsive>
|
|
252
|
+
{/* ... */}
|
|
253
|
+
</LineChart>
|
|
254
|
+
|
|
255
|
+
// BAD: Fixed size - won't adapt to container changes
|
|
256
|
+
<LineChart width={600} height={300} data={data}>
|
|
257
|
+
{/* ... */}
|
|
258
|
+
</LineChart>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### 2. Use ResponsiveContainer (older versions)
|
|
262
|
+
|
|
263
|
+
For Recharts < 3.3, wrap the chart in `ResponsiveContainer`:
|
|
264
|
+
|
|
265
|
+
```jsx
|
|
266
|
+
<ResponsiveContainer width="100%" height={300}>
|
|
267
|
+
<LineChart data={data}>
|
|
268
|
+
{/* ... */}
|
|
269
|
+
</LineChart>
|
|
270
|
+
</ResponsiveContainer>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Important**: `ResponsiveContainer` must have a parent with defined dimensions. Height must be a number, not a percentage.
|
|
274
|
+
|
|
275
|
+
### 3. Handle Container Sizing
|
|
276
|
+
|
|
277
|
+
Ensure parent container has defined dimensions (applies to both `responsive` prop and `ResponsiveContainer`):
|
|
278
|
+
|
|
279
|
+
```jsx
|
|
280
|
+
// Parent must have explicit height or flex layout
|
|
281
|
+
<div style={{ width: '100%', height: '400px' }}>
|
|
282
|
+
<LineChart data={data} responsive style={{ width: '100%', height: '100%' }}>
|
|
283
|
+
{/* ... */}
|
|
284
|
+
</LineChart>
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
// OR using flexbox
|
|
288
|
+
<div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
|
|
289
|
+
<div style={{ flex: 1 }}>
|
|
290
|
+
<LineChart data={data} responsive style={{ width: '100%', height: '100%' }}>
|
|
291
|
+
{/* ... */}
|
|
292
|
+
</LineChart>
|
|
293
|
+
</div>
|
|
294
|
+
</div>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### 3. Adjust for Small Screens
|
|
298
|
+
|
|
299
|
+
```jsx
|
|
300
|
+
import { useMediaQuery } from 'react-responsive';
|
|
301
|
+
|
|
302
|
+
function AdaptiveChart({ data }) {
|
|
303
|
+
const isMobile = useMediaQuery({ maxWidth: 768 });
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<LineChart data={data} responsive style={{ width: '100%', height: isMobile ? 200 : 400 }}>
|
|
307
|
+
<XAxis
|
|
308
|
+
dataKey="name"
|
|
309
|
+
interval={isMobile ? 'preserveEnd' : 0}
|
|
310
|
+
angle={isMobile ? -45 : 0}
|
|
311
|
+
height={isMobile ? 50 : 30}
|
|
312
|
+
/>
|
|
313
|
+
<YAxis width={isMobile ? 30 : 60} />
|
|
314
|
+
<Tooltip />
|
|
315
|
+
{/* Reduce chart complexity on mobile */}
|
|
316
|
+
{!isMobile && <Legend />}
|
|
317
|
+
<Line type="monotone" dataKey="value" stroke="#8884d8" />
|
|
318
|
+
</LineChart>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### 4. Aspect Ratio Preservation
|
|
324
|
+
|
|
325
|
+
```jsx
|
|
326
|
+
<LineChart data={data} responsive style={{ width: '100%', aspectRatio: '16/9' }}>
|
|
327
|
+
{/* ... */}
|
|
328
|
+
</LineChart>
|
|
329
|
+
|
|
330
|
+
{/* Or with ResponsiveContainer (older versions): */}
|
|
331
|
+
<ResponsiveContainer width="100%" aspect={16 / 9}>
|
|
332
|
+
<LineChart>{/* ... */}</LineChart>
|
|
333
|
+
</ResponsiveContainer>
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Accessibility
|
|
337
|
+
|
|
338
|
+
### 1. Enable Accessibility Layer
|
|
339
|
+
|
|
340
|
+
Enabled by default, but can be explicitly set:
|
|
341
|
+
|
|
342
|
+
```jsx
|
|
343
|
+
<LineChart accessibilityLayer={true}>
|
|
344
|
+
{/* Components */}
|
|
345
|
+
</LineChart>
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### 2. Add ARIA Labels
|
|
349
|
+
|
|
350
|
+
```jsx
|
|
351
|
+
<LineChart
|
|
352
|
+
role="img"
|
|
353
|
+
aria-label="Line chart showing monthly sales from January to June 2024"
|
|
354
|
+
>
|
|
355
|
+
{/* Components */}
|
|
356
|
+
</LineChart>
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 3. Provide Text Alternatives
|
|
360
|
+
|
|
361
|
+
Always include descriptive text near charts:
|
|
362
|
+
|
|
363
|
+
```jsx
|
|
364
|
+
<figure>
|
|
365
|
+
<LineChart data={data} responsive style={{ width: '100%', height: 300 }}>
|
|
366
|
+
{/* ... */}
|
|
367
|
+
</LineChart>
|
|
368
|
+
<figcaption>
|
|
369
|
+
Sales increased 25% from January to June 2024,
|
|
370
|
+
with the highest sales in June at $9,800.
|
|
371
|
+
</figcaption>
|
|
372
|
+
</figure>
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### 4. Keyboard Navigation
|
|
376
|
+
|
|
377
|
+
Charts are keyboard navigable by default when `accessibilityLayer` is enabled (which it is by default). The chart's `tabIndex` prop controls where it appears in the tab order:
|
|
378
|
+
|
|
379
|
+
```jsx
|
|
380
|
+
<LineChart tabIndex={0} accessibilityLayer>
|
|
381
|
+
{/* Components */}
|
|
382
|
+
</LineChart>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### 5. Color Contrast
|
|
386
|
+
|
|
387
|
+
Ensure sufficient contrast for all chart elements:
|
|
388
|
+
|
|
389
|
+
```jsx
|
|
390
|
+
<LineChart>
|
|
391
|
+
<Line stroke="#1f77b4" /> // Good contrast on white
|
|
392
|
+
<Line stroke="#ff7f0e" /> // Good contrast on white
|
|
393
|
+
{/* Avoid: stroke="#ddd" on white background */}
|
|
394
|
+
</LineChart>
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### 6. Don't Rely on Color Alone
|
|
398
|
+
|
|
399
|
+
Use patterns, labels, or different line styles:
|
|
400
|
+
|
|
401
|
+
```jsx
|
|
402
|
+
<LineChart>
|
|
403
|
+
<Line
|
|
404
|
+
type="monotone"
|
|
405
|
+
dataKey="sales"
|
|
406
|
+
stroke="#8884d8"
|
|
407
|
+
strokeWidth={2}
|
|
408
|
+
name="Sales (solid line)"
|
|
409
|
+
/>
|
|
410
|
+
<Line
|
|
411
|
+
type="monotone"
|
|
412
|
+
dataKey="profit"
|
|
413
|
+
stroke="#82ca9d"
|
|
414
|
+
strokeWidth={2}
|
|
415
|
+
strokeDasharray="5 5"
|
|
416
|
+
name="Profit (dashed line)"
|
|
417
|
+
/>
|
|
418
|
+
<Legend />
|
|
419
|
+
</LineChart>
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Data Patterns
|
|
423
|
+
|
|
424
|
+
### 1. Data Shape
|
|
425
|
+
|
|
426
|
+
Recharts expects array of objects:
|
|
427
|
+
|
|
428
|
+
```javascript
|
|
429
|
+
// GOOD
|
|
430
|
+
const data = [
|
|
431
|
+
{ month: 'Jan', sales: 4000, profit: 2400 },
|
|
432
|
+
{ month: 'Feb', sales: 3000, profit: 1398 },
|
|
433
|
+
];
|
|
434
|
+
|
|
435
|
+
// BAD: Array of arrays
|
|
436
|
+
const badData = [
|
|
437
|
+
['Jan', 4000, 2400],
|
|
438
|
+
['Feb', 3000, 1398],
|
|
439
|
+
];
|
|
440
|
+
|
|
441
|
+
// BAD: Object of arrays
|
|
442
|
+
const alsoBad = {
|
|
443
|
+
months: ['Jan', 'Feb'],
|
|
444
|
+
sales: [4000, 3000],
|
|
445
|
+
};
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### 2. Handling Null/Undefined
|
|
449
|
+
|
|
450
|
+
```jsx
|
|
451
|
+
// Data with missing values
|
|
452
|
+
const data = [
|
|
453
|
+
{ month: 'Jan', sales: 4000 },
|
|
454
|
+
{ month: 'Feb', sales: null }, // Missing
|
|
455
|
+
{ month: 'Mar', sales: 3000 },
|
|
456
|
+
];
|
|
457
|
+
|
|
458
|
+
// Option 1: Connect through nulls
|
|
459
|
+
<Line type="monotone" dataKey="sales" connectNulls={true} />
|
|
460
|
+
|
|
461
|
+
// Option 2: Gap at null
|
|
462
|
+
<Line type="monotone" dataKey="sales" connectNulls={false} />
|
|
463
|
+
|
|
464
|
+
// Option 3: Pre-process to fill values
|
|
465
|
+
const filledData = data.map(item => ({
|
|
466
|
+
...item,
|
|
467
|
+
sales: item.sales ?? 0 // or interpolate
|
|
468
|
+
}));
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### 3. Data Pre-processing
|
|
472
|
+
|
|
473
|
+
Transform data before passing to Recharts:
|
|
474
|
+
|
|
475
|
+
```jsx
|
|
476
|
+
const Chart = ({ rawData }) => {
|
|
477
|
+
// Calculate derived values
|
|
478
|
+
const processedData = useMemo(() => {
|
|
479
|
+
return rawData.map(item => ({
|
|
480
|
+
...item,
|
|
481
|
+
total: item.q1 + item.q2 + item.q3 + item.q4,
|
|
482
|
+
average: (item.q1 + item.q2 + item.q3 + item.q4) / 4,
|
|
483
|
+
growth: ((item.q4 - item.q1) / item.q1) * 100
|
|
484
|
+
}));
|
|
485
|
+
}, [rawData]);
|
|
486
|
+
|
|
487
|
+
// Filter or sort if needed
|
|
488
|
+
const filteredData = useMemo(() => {
|
|
489
|
+
return processedData
|
|
490
|
+
.filter(item => item.total > 0)
|
|
491
|
+
.sort((a, b) => b.total - a.total);
|
|
492
|
+
}, [processedData]);
|
|
493
|
+
|
|
494
|
+
return (
|
|
495
|
+
<LineChart data={filteredData}>
|
|
496
|
+
{/* ... */}
|
|
497
|
+
</LineChart>
|
|
498
|
+
);
|
|
499
|
+
};
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### 4. Date/Time Handling
|
|
503
|
+
|
|
504
|
+
```jsx
|
|
505
|
+
import { format, parseISO } from 'date-fns';
|
|
506
|
+
|
|
507
|
+
const data = [
|
|
508
|
+
{ date: '2024-01-01', value: 100 },
|
|
509
|
+
{ date: '2024-02-01', value: 150 },
|
|
510
|
+
];
|
|
511
|
+
|
|
512
|
+
// Option 1: Format in data
|
|
513
|
+
const formattedData = data.map(d => ({
|
|
514
|
+
...d,
|
|
515
|
+
formattedDate: format(parseISO(d.date), 'MMM yyyy')
|
|
516
|
+
}));
|
|
517
|
+
|
|
518
|
+
<XAxis dataKey="formattedDate" />
|
|
519
|
+
|
|
520
|
+
// Option 2: Format with tickFormatter
|
|
521
|
+
<XAxis
|
|
522
|
+
dataKey="date"
|
|
523
|
+
tickFormatter={(date) => format(parseISO(date), 'MMM')}
|
|
524
|
+
/>
|
|
525
|
+
|
|
526
|
+
// Option 3: Use time scale with custom domain
|
|
527
|
+
<XAxis
|
|
528
|
+
dataKey="date"
|
|
529
|
+
type="number"
|
|
530
|
+
scale="time"
|
|
531
|
+
domain={['auto', 'auto']}
|
|
532
|
+
tickFormatter={(timestamp) => format(new Date(timestamp), 'MMM d')}
|
|
533
|
+
/>
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
## Visual Design
|
|
537
|
+
|
|
538
|
+
### 1. Consistent Color Palette
|
|
539
|
+
|
|
540
|
+
Define a color scheme:
|
|
541
|
+
|
|
542
|
+
```jsx
|
|
543
|
+
const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042', '#8884D8'];
|
|
544
|
+
|
|
545
|
+
// Use consistently
|
|
546
|
+
<Line stroke={COLORS[0]} />
|
|
547
|
+
<Line stroke={COLORS[1]} />
|
|
548
|
+
<Bar fill={COLORS[0]} />
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### 2. Typography
|
|
552
|
+
|
|
553
|
+
```jsx
|
|
554
|
+
<XAxis
|
|
555
|
+
tick={{ fontSize: 12, fontFamily: 'Arial, sans-serif', fill: '#666' }}
|
|
556
|
+
label={{ value: 'Month', fontSize: 14, fontWeight: 'bold', fill: '#333' }}
|
|
557
|
+
/>
|
|
558
|
+
|
|
559
|
+
<YAxis
|
|
560
|
+
tick={{ fontSize: 12, fill: '#666' }}
|
|
561
|
+
tickFormatter={(value) => `$${value.toLocaleString()}`}
|
|
562
|
+
/>
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
### 3. Spacing and Margins
|
|
566
|
+
|
|
567
|
+
```jsx
|
|
568
|
+
<LineChart margin={{ top: 20, right: 30, left: 20, bottom: 20 }}>
|
|
569
|
+
<XAxis dataKey="name" height={60} />
|
|
570
|
+
<YAxis width={80} />
|
|
571
|
+
{/* ... */}
|
|
572
|
+
</LineChart>
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
### 4. Grid Styling
|
|
576
|
+
|
|
577
|
+
```jsx
|
|
578
|
+
<CartesianGrid
|
|
579
|
+
strokeDasharray="3 3"
|
|
580
|
+
stroke="#e0e0e0"
|
|
581
|
+
vertical={true}
|
|
582
|
+
horizontal={true}
|
|
583
|
+
/>
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### 5. Legends
|
|
587
|
+
|
|
588
|
+
```jsx
|
|
589
|
+
<Legend
|
|
590
|
+
verticalAlign="top"
|
|
591
|
+
height={36}
|
|
592
|
+
iconType="circle"
|
|
593
|
+
wrapperStyle={{ paddingTop: 20 }}
|
|
594
|
+
/>
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
### 6. Tooltips
|
|
598
|
+
|
|
599
|
+
```jsx
|
|
600
|
+
<Tooltip
|
|
601
|
+
contentStyle={{
|
|
602
|
+
backgroundColor: '#fff',
|
|
603
|
+
border: '1px solid #ccc',
|
|
604
|
+
borderRadius: '4px',
|
|
605
|
+
padding: '10px',
|
|
606
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)'
|
|
607
|
+
}}
|
|
608
|
+
labelStyle={{ fontWeight: 'bold', marginBottom: '8px' }}
|
|
609
|
+
itemStyle={{ fontSize: '14px' }}
|
|
610
|
+
separator={": "}
|
|
611
|
+
/>
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
## Testing and Debugging
|
|
615
|
+
|
|
616
|
+
### 1. Use Recharts DevTools
|
|
617
|
+
|
|
618
|
+
Install devtools for debugging:
|
|
619
|
+
|
|
620
|
+
```bash
|
|
621
|
+
npm install @recharts/devtools
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
```jsx
|
|
625
|
+
import { RechartsDevtools } from '@recharts/devtools';
|
|
626
|
+
|
|
627
|
+
<LineChart data={data}>
|
|
628
|
+
{/* ... */}
|
|
629
|
+
<RechartsDevtools /> // Shows hook inspector
|
|
630
|
+
</LineChart>
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### 2. Testing Chart Components
|
|
634
|
+
|
|
635
|
+
```jsx
|
|
636
|
+
import { render, screen } from '@testing-library/react';
|
|
637
|
+
import { LineChart, Line, XAxis, YAxis, ResponsiveContainer } from 'recharts';
|
|
638
|
+
|
|
639
|
+
describe('ChartComponent', () => {
|
|
640
|
+
const mockData = [
|
|
641
|
+
{ name: 'A', value: 10 },
|
|
642
|
+
{ name: 'B', value: 20 },
|
|
643
|
+
];
|
|
644
|
+
|
|
645
|
+
it('renders without crashing', () => {
|
|
646
|
+
render(
|
|
647
|
+
<div style={{ width: '400px', height: '300px' }}>
|
|
648
|
+
<ResponsiveContainer>
|
|
649
|
+
<LineChart data={mockData}>
|
|
650
|
+
<XAxis dataKey="name" />
|
|
651
|
+
<YAxis />
|
|
652
|
+
<Line dataKey="value" />
|
|
653
|
+
</LineChart>
|
|
654
|
+
</ResponsiveContainer>
|
|
655
|
+
</div>
|
|
656
|
+
);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('displays correct data', () => {
|
|
660
|
+
render(<ChartComponent data={mockData} />);
|
|
661
|
+
// Check for aria-label or figcaption content
|
|
662
|
+
expect(screen.getByLabelText(/sales chart/i)).toBeInTheDocument();
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
### 3. Debugging Tips
|
|
668
|
+
|
|
669
|
+
- Check that parent container has explicit dimensions
|
|
670
|
+
- Verify data is array of objects
|
|
671
|
+
- Ensure all `dataKey` values exist in data
|
|
672
|
+
- Look for console warnings about prop types
|
|
673
|
+
- Use React DevTools to inspect re-renders
|
|
674
|
+
|
|
675
|
+
## Common Pitfalls
|
|
676
|
+
|
|
677
|
+
### 1. Chart Without Defined Size
|
|
678
|
+
|
|
679
|
+
```jsx
|
|
680
|
+
// WRONG: No dimensions specified
|
|
681
|
+
<LineChart data={data}>
|
|
682
|
+
{/* ... */}
|
|
683
|
+
</LineChart>
|
|
684
|
+
|
|
685
|
+
// CORRECT: Use responsive prop with CSS sizing (Recharts 3.3+)
|
|
686
|
+
<LineChart data={data} responsive style={{ width: '100%', height: 300 }}>
|
|
687
|
+
{/* ... */}
|
|
688
|
+
</LineChart>
|
|
689
|
+
|
|
690
|
+
// CORRECT: Static pixel dimensions
|
|
691
|
+
<LineChart data={data} width={600} height={300}>
|
|
692
|
+
{/* ... */}
|
|
693
|
+
</LineChart>
|
|
694
|
+
|
|
695
|
+
// CORRECT: ResponsiveContainer (older versions) - parent must have defined height
|
|
696
|
+
<div style={{ height: '300px' }}>
|
|
697
|
+
<ResponsiveContainer>
|
|
698
|
+
<LineChart data={data}>{/* ... */}</LineChart>
|
|
699
|
+
</ResponsiveContainer>
|
|
700
|
+
</div>
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
### 2. Missing dataKey
|
|
704
|
+
|
|
705
|
+
```jsx
|
|
706
|
+
// WRONG
|
|
707
|
+
<XAxis /> // No dataKey - won't show labels
|
|
708
|
+
|
|
709
|
+
// CORRECT
|
|
710
|
+
<XAxis dataKey="name" />
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### 3. Unstable References
|
|
714
|
+
|
|
715
|
+
```jsx
|
|
716
|
+
// WRONG: New array every render
|
|
717
|
+
<LineChart data={getData()}>
|
|
718
|
+
|
|
719
|
+
// CORRECT: Memoized data
|
|
720
|
+
const data = useMemo(() => getData(), []);
|
|
721
|
+
<LineChart data={data}>
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
### 4. Incorrect Percentage in ResponsiveContainer
|
|
725
|
+
|
|
726
|
+
```jsx
|
|
727
|
+
// WRONG: Height cannot be percentage in ResponsiveContainer
|
|
728
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
729
|
+
|
|
730
|
+
// CORRECT: Height must be number in ResponsiveContainer
|
|
731
|
+
<ResponsiveContainer width="100%" height={300}>
|
|
732
|
+
// OR use aspect
|
|
733
|
+
<ResponsiveContainer width="100%" aspect={2}>
|
|
734
|
+
|
|
735
|
+
// BETTER (Recharts 3.3+): Use responsive prop — supports CSS percentages
|
|
736
|
+
<LineChart data={data} responsive style={{ width: '100%', height: '100%' }}>
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
### 5. Overlapping Labels
|
|
740
|
+
|
|
741
|
+
```jsx
|
|
742
|
+
// Solution: Rotate labels
|
|
743
|
+
<XAxis
|
|
744
|
+
dataKey="name"
|
|
745
|
+
angle={-45}
|
|
746
|
+
textAnchor="end"
|
|
747
|
+
height={80}
|
|
748
|
+
/>
|
|
749
|
+
|
|
750
|
+
// OR reduce tick count
|
|
751
|
+
<XAxis dataKey="name" interval="preserveStartEnd" />
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### 6. Ignoring Performance Warnings
|
|
755
|
+
|
|
756
|
+
Always check for:
|
|
757
|
+
- Creating new functions in render
|
|
758
|
+
- Not memoizing data transformations
|
|
759
|
+
- Animating large datasets
|
|
760
|
+
- Not using `isAnimationActive={false}` for real-time
|
|
761
|
+
|
|
762
|
+
## ESLint Configuration
|
|
763
|
+
|
|
764
|
+
Use eslint-plugin-react-perf to catch performance issues:
|
|
765
|
+
|
|
766
|
+
```json
|
|
767
|
+
{
|
|
768
|
+
"extends": ["plugin:react-perf/recommended"],
|
|
769
|
+
"rules": {
|
|
770
|
+
"react-perf/jsx-no-new-object-as-prop": "warn",
|
|
771
|
+
"react-perf/jsx-no-new-array-as-prop": "warn",
|
|
772
|
+
"react-perf/jsx-no-new-function-as-prop": "warn"
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
## Resources
|
|
778
|
+
|
|
779
|
+
- [Official Performance Guide](https://recharts.github.io/en-US/guide/performance)
|
|
780
|
+
- [React.memo Documentation](https://react.dev/reference/react/memo)
|
|
781
|
+
- [useMemo Documentation](https://react.dev/reference/react/useMemo)
|
|
782
|
+
- [useCallback Documentation](https://react.dev/reference/react/useCallback)
|