-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathwithNodeRelease.tsx
More file actions
34 lines (26 loc) · 906 Bytes
/
withNodeRelease.tsx
File metadata and controls
34 lines (26 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use server';
import provideReleaseData from '#site/next-data/providers/releaseData';
import type { NodeRelease, NodeReleaseStatus } from '#site/types';
import type { FC } from 'react';
type WithNodeReleaseProps = {
status: Array<NodeReleaseStatus> | NodeReleaseStatus;
children: FC<{ release: NodeRelease }>;
};
// This is a React Async Server Component
// Note that Hooks cannot be used in a RSC async component
// Async Components do not get re-rendered at all.
const WithNodeRelease: FC<WithNodeReleaseProps> = async ({
status: statuses,
children: Component,
}) => {
const releases = await provideReleaseData();
const matchingRelease = [statuses]
.flat()
.map(status => releases.find(release => release.status === status))
.find(Boolean);
if (matchingRelease) {
return <Component release={matchingRelease} />;
}
return null;
};
export default WithNodeRelease;