-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserver-side-rendering-pure.tsx
53 lines (50 loc) · 1.68 KB
/
server-side-rendering-pure.tsx
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 * as React from "react";
import { GetServerSideProps } from "next";
import { Layout } from "components/Layout";
import { Result } from "components/Result";
import { getFlags, type EvaluationResponseBody } from "flags/server";
import type { AppFlags } from "flags/config";
type ServerSideProps = {
flags: AppFlags | null;
data: EvaluationResponseBody | null;
};
export const getServerSideProps: GetServerSideProps<ServerSideProps> = async (
context
) => {
const { flags, data } = await getFlags({ context });
return { props: { flags, data } };
};
export default function Page(props: ServerSideProps) {
return (
<Layout
title="Server Side Rendering (Pure)"
source={`https://github.com/happykit/flags/blob/${process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF}/example/pages/demo/server-side-rendering-pure.tsx`}
flagBag={null}
>
<article className="py-4 prose max-w-prose">
<p>
This demo shows how to use <code>@happykit/flags</code> for
server-rendered pages.
</p>
<p>
Since this page is rendered on the server only, there is no{" "}
<code>flagBag</code>. Instead, the values are shown directly.
</p>
<Result
key="server-side-rendering-pure"
label="Flags"
value={props.flags}
/>
<p>
Aside from the flags, we have access to the loaded flags as well.
These are the flags without any fallback values.
</p>
<Result
key="server-side-rendering-pure-with-fallback-values"
label="Loaded data (without fallback values)"
value={props.data}
/>
</article>
</Layout>
);
}