import { useEffect } from 'react'; type PreloadAs = 'font' | 'image' | 'style' | 'script'; export function PreloadResource({ href, as }: { href: string; as: PreloadAs }) { useEffect(() => { // TODO: // 1) document.head에 이미 link[rel="preload"][href={href}] 가 있으면 return // 2) <link rel="preload" as={as} href={href}> 생성 // 3) as === 'font' 이면 crossorigin="anonymous" 속성 추가 // 4) document.head.appendChild(link) throw new Error('Not implemented'); }, [href, as]); return null; }
Tests