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