-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[userId].tsx
More file actions
53 lines (41 loc) · 1.19 KB
/
Copy path[userId].tsx
File metadata and controls
53 lines (41 loc) · 1.19 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { GetServerSideProps, NextPage } from "next";
import Script from "next/script";
import { useId, useMemo } from "react";
import { getProfile, Profile } from "../../lib/query";
type ProfilePageProps = {
profile: Profile;
browserTimingScript: string;
};
const ProfilePage: NextPage<ProfilePageProps> = ({
profile,
browserTimingScript,
}) => {
const id = useId();
const json = useMemo(() => JSON.stringify(profile, null, 2), [profile]);
return (
<main style={{ padding: "24px" }}>
<Script id={id} strategy="afterInteractive">
{browserTimingScript}
</Script>
<p style={{ whiteSpace: "pre-wrap" }}>{json}</p>
</main>
);
};
export default ProfilePage;
export const getServerSideProps: GetServerSideProps<ProfilePageProps> = async ({
query,
}) => {
const { userId } = query;
if (typeof userId !== "string") {
return { notFound: true };
}
const profile = await getProfile(userId);
if (!profile) {
return { notFound: true };
}
const newrelic = await import("newrelic");
const browserTimingScript = await newrelic.getBrowserTimingHeader({
hasToRemoveScriptWrapper: true,
});
return { props: { profile, browserTimingScript } };
};