The Node.js® Website
at main 836 B view raw
1import type { FC } from 'react'; 2 3import getReleaseData from '@/next-data/releaseData'; 4import type { NodeRelease, NodeReleaseStatus } from '@/types'; 5 6type WithNodeReleaseProps = { 7 status: Array<NodeReleaseStatus> | NodeReleaseStatus; 8 children: FC<{ release: NodeRelease }>; 9}; 10 11// This is a React Async Server Component 12// Note that Hooks cannot be used in a RSC async component 13// Async Components do not get re-rendered at all. 14const WithNodeRelease: FC<WithNodeReleaseProps> = async ({ 15 status, 16 children: Component, 17}) => { 18 const releaseData = await getReleaseData(); 19 20 const matchingRelease = releaseData.find(release => 21 [status].flat().includes(release.status) 22 ); 23 24 if (matchingRelease !== undefined) { 25 return <Component release={matchingRelease!} />; 26 } 27 28 return null; 29}; 30 31export default WithNodeRelease;