|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import React, { useEffect, useState } from 'react'; |
| 3 | +import React, { useEffect, useMemo, useState } from 'react'; |
4 | 4 | import { useQuery } from '@tanstack/react-query'; |
5 | | -import Image from 'next/image'; |
| 5 | +import Image, { StaticImageData } from 'next/image'; |
6 | 6 | import PopularContents from '@/components/learning/PopularContents'; |
7 | 7 | import RecentContents from '@/components/learning/RecentContents'; |
8 | 8 | import LatestNewsClipping from '@/components/learning/LatestNewsClipping'; |
@@ -82,13 +82,27 @@ const LearningPageClient = ({ initialData }: { initialData: OverviewResponse }) |
82 | 82 | })) |
83 | 83 | : []; |
84 | 84 |
|
85 | | - const categoryInfo = categoryConfig[selectedCategory as keyof typeof categoryConfig] || categoryConfig.all; |
86 | | - |
87 | | - |
| 85 | + const categoryInfo = useMemo(() => { |
| 86 | + return categoryConfig[selectedCategory as keyof typeof categoryConfig] || categoryConfig.all; |
| 87 | + }, [selectedCategory]); |
| 88 | + |
| 89 | + const preloadImage = (src: StaticImageData) => { |
| 90 | + const img = new window.Image(); |
| 91 | + img.src = src.src; |
| 92 | + }; |
| 93 | + |
| 94 | + useEffect(() => { |
| 95 | + if (selectedCategory) { |
| 96 | + preloadImage(categoryConfig[selectedCategory as keyof typeof categoryConfig].backgroundImage); |
| 97 | + } |
| 98 | + }, [selectedCategory]); |
| 99 | + |
| 100 | + |
88 | 101 | return ( |
89 | 102 | <div> |
90 | 103 | <div className="hidden sm:flex relative w-full h-[300px] lg:h-[400px]"> |
91 | 104 | <Image |
| 105 | + key={categoryInfo.backgroundImage.src} |
92 | 106 | src={categoryInfo.backgroundImage} |
93 | 107 | alt="Background" |
94 | 108 | layout="fill" |
|
0 commit comments