diff --git a/src/components/Roadmaps/RoadmapCard.tsx b/src/components/Roadmaps/RoadmapCard.tsx new file mode 100644 index 000000000..f7e43ccaa --- /dev/null +++ b/src/components/Roadmaps/RoadmapCard.tsx @@ -0,0 +1,31 @@ +import { useIsMounted } from '../../hooks/use-is-mounted'; +import { MarkFavorite } from '../FeaturedItems/MarkFavorite'; +import type { GroupType } from './RoadmapsPage'; + +type RoadmapCardProps = { + roadmap: GroupType['roadmaps'][number]; +}; + +export function RoadmapCard(props: RoadmapCardProps) { + const { roadmap } = props; + + const isMounted = useIsMounted(); + + return ( + + {roadmap.title} + + {isMounted && ( + + )} + + ); +} diff --git a/src/components/Roadmaps/RoadmapsPage.tsx b/src/components/Roadmaps/RoadmapsPage.tsx index eb1c4896a..fe37cf00c 100644 --- a/src/components/Roadmaps/RoadmapsPage.tsx +++ b/src/components/Roadmaps/RoadmapsPage.tsx @@ -8,6 +8,7 @@ import { getUrlParams, setUrlParams, } from '../../lib/browser.ts'; +import { RoadmapCard } from './RoadmapCard.tsx'; const groupNames = [ 'Absolute Beginners', @@ -27,7 +28,7 @@ const groupNames = [ type AllowGroupNames = (typeof groupNames)[number]; -type GroupType = { +export type GroupType = { group: AllowGroupNames; roadmaps: { title: string; @@ -547,13 +548,7 @@ export function RoadmapsPage() {
{group.roadmaps.map((roadmap) => ( - - {roadmap.title} - + ))}
diff --git a/src/hooks/use-is-mounted.ts b/src/hooks/use-is-mounted.ts new file mode 100644 index 000000000..ee266e9b2 --- /dev/null +++ b/src/hooks/use-is-mounted.ts @@ -0,0 +1,13 @@ +import { useEffect, useState } from 'react'; + +export function useIsMounted() { + const [isMounted, setIsMounted] = useState(false); + useEffect(() => { + setIsMounted(true); + + return () => { + setIsMounted(false); + }; + }, []); + return isMounted; +}