Performance and Reusability #25
Reference in New Issue
Block a user
Delete Branch "adilallo/enhancement/PerformanceandReusability"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Extract Custom Hooks & Implement Code Splitting
Overview
This PR implements two performance and code organization improvements:
These changes improve code organization, reduce bundle size, and maintain performance while keeping all existing functionality intact.
Changes
Custom Hooks (8 hooks created)
useClickOutside- Detects clicks outside elements (used in Select.tsx)useAnalytics- Centralized analytics tracking (used in AskOrganizer.tsx)useComponentId- Generates unique component IDs for accessibilityuseFormField- Form field event handlers with disabled state handlinguseComponentStyles- Component size/state styling patternsuseSchemaData- Generates Schema.org structured data (JSON-LD)useMediaQuery- Responsive breakpoint detection with convenience hooksuseFormValidation- Form validation logic with common validation rulesComponents Refactored (7 components)
Select.tsx- UsesuseClickOutsideAskOrganizer.tsx- UsesuseAnalyticsInput.tsx- UsesuseComponentIdanduseFormFieldTextArea.tsx- UsesuseComponentIdanduseFormFieldCheckbox.tsx- UsesuseComponentIdNumberedCards.tsx- UsesuseSchemaDataRelatedArticles.tsx- UsesuseIsMobileCode Splitting Implementation
app/layout.tsx) - Below-the-fold, lazy loaded with SSRapp/page.tsx) - LogoWall, NumberedCards, RuleStack, FeatureGrid, QuoteBlockapp/blog/[slug]/page.tsx) - RelatedArticles (blog-specific)Testing & Documentation
tests/unit/hooks/)docs/CUSTOM_HOOKS.md)next/dynamicin test environmentFiles Added
app/hooks/useClickOutside.tsapp/hooks/useAnalytics.tsapp/hooks/useComponentId.tsapp/hooks/useFormField.tsapp/hooks/useComponentStyles.tsapp/hooks/useSchemaData.tsapp/hooks/useMediaQuery.tsapp/hooks/useFormValidation.tsapp/hooks/index.tstests/unit/hooks/useClickOutside.test.jsxtests/unit/hooks/useComponentId.test.jsxtests/unit/hooks/useSchemaData.test.jsxdocs/CUSTOM_HOOKS.mdFiles Modified
app/components/Select.tsxapp/components/AskOrganizer.tsxapp/components/Input.tsxapp/components/TextArea.tsxapp/components/Checkbox.tsxapp/components/NumberedCards.tsxapp/components/RelatedArticles.tsxapp/layout.tsxapp/page.tsxapp/blog/[slug]/page.tsxvitest.setup.tstests/unit/Page.test.jsxtests/unit/AskOrganizer.test.jsxScreenshots
N/A - Performance and code organization improvements, no visual changes
How to Test
npm run build