UNPKG

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