1 | import * as React from 'react';
|
2 | import { CurrentRenderContext } from '@react-navigation/core';
|
3 | import ServerContext from './ServerContext';
|
4 |
|
5 | /**
|
6 | * Container component for server rendering.
|
7 | *
|
8 | * @param props.location Location object to base the initial URL for SSR.
|
9 | * @param props.children Child elements to render the content.
|
10 | * @param props.ref Ref object which contains helper methods.
|
11 | */
|
12 | export default /*#__PURE__*/React.forwardRef(function ServerContainer({
|
13 | children,
|
14 | location
|
15 | }, ref) {
|
16 | React.useEffect(() => {
|
17 | console.error("'ServerContainer' should only be used on the server with 'react-dom/server' for SSR.");
|
18 | }, []);
|
19 | const current = {};
|
20 |
|
21 | if (ref) {
|
22 | const value = {
|
23 | getCurrentOptions() {
|
24 | return current.options;
|
25 | }
|
26 |
|
27 | }; // We write to the `ref` during render instead of `React.useImperativeHandle`
|
28 | // This is because `useImperativeHandle` will update the ref after 'commit',
|
29 | // and there's no 'commit' phase during SSR.
|
30 | // Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR.
|
31 |
|
32 | if (typeof ref === 'function') {
|
33 | ref(value);
|
34 | } else {
|
35 | // @ts-expect-error: the TS types are incorrect and say that ref.current is readonly
|
36 | ref.current = value;
|
37 | }
|
38 | }
|
39 |
|
40 | return /*#__PURE__*/React.createElement(ServerContext.Provider, {
|
41 | value: {
|
42 | location
|
43 | }
|
44 | }, /*#__PURE__*/React.createElement(CurrentRenderContext.Provider, {
|
45 | value: current
|
46 | }, children));
|
47 | });
|
48 | //# sourceMappingURL=ServerContainer.js.map |
\ | No newline at end of file |