forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-context.ts
More file actions
24 lines (20 loc) · 850 Bytes
/
client-context.ts
File metadata and controls
24 lines (20 loc) · 850 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
import { cache } from 'react';
import type { ClientSharedServerContext } from '@/types';
// This allows us to have Server-Side Context's of the shared "contextual" data
// which includes the frontmatter, the current pathname from the dynamic segments
// and the current headings of the current markdown context
export const getClientContext = cache(() => {
const serverSharedContext: ClientSharedServerContext = {
frontmatter: {},
pathname: '',
headings: [],
};
return serverSharedContext;
});
// This is used by the dynamic router to define on the request
// the current set of information we use (shared)
export const setClientContext = (data: ClientSharedServerContext) => {
getClientContext().frontmatter = data.frontmatter;
getClientContext().pathname = data.pathname;
getClientContext().headings = data.headings;
};