UNPKG

883 BJavaScriptView Raw
1import * as React from 'react';
2
3const NavigationContent = _ref => {
4 let {
5 render,
6 children
7 } = _ref;
8 return render(children);
9};
10
11export default function useComponent(render) {
12 const renderRef = React.useRef(render); // Normally refs shouldn't be mutated in render
13 // But we return a component which will be rendered
14 // So it's just for immediate consumption
15
16 renderRef.current = render;
17 React.useEffect(() => {
18 renderRef.current = null;
19 });
20 return React.useRef(_ref2 => {
21 let {
22 children
23 } = _ref2;
24 const render = renderRef.current;
25
26 if (render === null) {
27 throw new Error('The returned component must be rendered in the same render phase as the hook.');
28 }
29
30 return /*#__PURE__*/React.createElement(NavigationContent, {
31 render: render
32 }, children);
33 }).current;
34}
35//# sourceMappingURL=useComponent.js.map
\No newline at end of file