1 | import { CurrentRenderContext } from '@react-navigation/core';
|
2 | import * as React from 'react';
|
3 |
|
4 | import ServerContext, { ServerContextType } from './ServerContext';
|
5 | import type { ServerContainerRef } from './types';
|
6 |
|
7 | type Props = ServerContextType & {
|
8 | children: React.ReactNode;
|
9 | };
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export default React.forwardRef(function ServerContainer(
|
19 | { children, location }: Props,
|
20 | ref: React.Ref<ServerContainerRef>
|
21 | ) {
|
22 | React.useEffect(() => {
|
23 | console.error(
|
24 | "'ServerContainer' should only be used on the server with 'react-dom/server' for SSR."
|
25 | );
|
26 | }, []);
|
27 |
|
28 | const current: { options?: object } = {};
|
29 |
|
30 | if (ref) {
|
31 | const value = {
|
32 | getCurrentOptions() {
|
33 | return current.options;
|
34 | },
|
35 | };
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | if (typeof ref === 'function') {
|
42 | ref(value);
|
43 | } else {
|
44 |
|
45 | ref.current = value;
|
46 | }
|
47 | }
|
48 |
|
49 | return (
|
50 | <ServerContext.Provider value={{ location }}>
|
51 | <CurrentRenderContext.Provider value={current}>
|
52 | {children}
|
53 | </CurrentRenderContext.Provider>
|
54 | </ServerContext.Provider>
|
55 | );
|
56 | });
|