-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlContext.tsx
34 lines (29 loc) · 1.06 KB
/
urlContext.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
import { createContext, useContext } from "react";
import * as React from "react";
const UrlContext = createContext({});
export function UrlContextWrapper({ children }) {
let sharedState = {};
if (typeof window !== "undefined") {
sharedState = {
meUrl: (window as any).GATSBY_ME_URL ?? process.env.GATSBY_ME_URL,
apiUrl: (window as any).GATSBY_API_URL ?? process.env.GATSBY_API_URL,
baseUrl: (window as any).GATSBY_BASE_URL ?? process.env.GATSBY_BASE_URL,
frontendUrl:
(window as any).GATSBY_FRONTEND_URL ?? process.env.GATSBY_FRONTEND_URL,
organization:
(window as any).GATSBY_ORGANIZATION ?? process.env.GATSBY_ORGANIZATION,
loginRedirect:
(window as any).GATSBY_LOGIN_REDIRECT ??
process.env.GATSBY_LOGIN_REDIRECT,
defaultTheme:
(window as any).GATSBY_DEFAULT_THEME ??
process.env.GATSBY_DEFAULT_THEME,
};
}
return (
<UrlContext.Provider value={sharedState}>{children}</UrlContext.Provider>
);
}
export function useUrlContext() {
return useContext(UrlContext);
}