Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/section.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use client";

import { ReactNode, useEffect, useRef, useState } from "react";
import { memo, ReactNode, useEffect, useRef, useState } from "react";

export const Section = ({
// ⚡ Optimization: Section component is memoized to prevent redundant re-renders of the section wrapper.
export const Section = memo(({
id,
title,
children,
Expand Down Expand Up @@ -62,4 +63,6 @@ export const Section = ({
</div>
</section>
);
};
});

Section.displayName = "Section";
11 changes: 9 additions & 2 deletions src/components/sections/education.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import Image from "next/image";

import degreesData from "@/data/degrees";

import { memo } from "react";

import { Section } from "../section";

export const EducationSection = () => {
// ⚡ Optimization: EducationSection is memoized to prevent unnecessary re-renders.
// Since it only depends on static data (degreesData) and doesn't consume filter/search contexts,
// it should only re-render if its parent (Home) re-renders, which we also want to avoid.
export const EducationSection = memo(() => {
return (
<Section id="degrees" title="Education">
{degreesData.map((degree) => (
Expand Down Expand Up @@ -36,4 +41,6 @@ export const EducationSection = () => {
))}
</Section>
);
};
});

EducationSection.displayName = "EducationSection";
26 changes: 16 additions & 10 deletions src/components/sections/skills.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ export const SkillsSection = () => {
const { debouncedQuery } = useSearch();
const { selected } = useFilter();

const filteredSkills = useMemo(() => {
const lowercaseQuery = debouncedQuery.toLowerCase();
const areas = selected["areas"];

// Determine which skills are matching the area filter
const selectedAreas = selected["areas"] || [];
const areaMatchingSkills = new Set<string>();
if (selectedAreas.length === 0) {
Object.keys(skillsData).forEach((s) => areaMatchingSkills.add(s));
// ⚡ Optimization: Memoize areaMatchingSkills separately from the query filter.
// This avoids re-calculating the matching skills set when only the search query changes.
const areaMatchingSkills = useMemo(() => {
const matchingSkills = new Set<string>();
if (!areas || areas.length === 0) {
Object.keys(skillsData).forEach((s) => matchingSkills.add(s));
} else {
selectedAreas.forEach((area) => {
areaSkills[area]?.forEach((skill) => areaMatchingSkills.add(skill));
areas.forEach((area) => {
areaSkills[area]?.forEach((skill) => matchingSkills.add(skill));
});
}
return matchingSkills;
}, [areas]);

// ⚡ Optimization: filteredSkills now only depends on debouncedQuery and the memoized areaMatchingSkills.
const filteredSkills = useMemo(() => {
const lowercaseQuery = debouncedQuery.toLowerCase();

return Object.entries(skillsData).filter(([key, skill]) => {
const matchesQuery =
!lowercaseQuery || skill.name.toLowerCase().includes(lowercaseQuery);
const matchesArea = areaMatchingSkills.has(key);
return matchesQuery && matchesArea;
});
}, [debouncedQuery, selected]);
}, [debouncedQuery, areaMatchingSkills]);

return (
<Section id="skills" title="Technical Skills">
Expand Down