UNPKG

1.86 kBSource Map (JSON)View Raw
1{"version":3,"names":["React","NavigationContent","render","children","useComponent","renderRef","useRef","current","useEffect","Error"],"sources":["useComponent.tsx"],"sourcesContent":["import * as React from 'react';\n\ntype Render = (children: React.ReactNode) => JSX.Element;\n\ntype Props = {\n render: Render;\n children: React.ReactNode;\n};\n\nconst NavigationContent = ({ render, children }: Props) => {\n return render(children);\n};\n\nexport default function useComponent(render: Render) {\n const renderRef = React.useRef<Render | null>(render);\n\n // Normally refs shouldn't be mutated in render\n // But we return a component which will be rendered\n // So it's just for immediate consumption\n renderRef.current = render;\n\n React.useEffect(() => {\n renderRef.current = null;\n });\n\n return React.useRef(({ children }: { children: React.ReactNode }) => {\n const render = renderRef.current;\n\n if (render === null) {\n throw new Error(\n 'The returned component must be rendered in the same render phase as the hook.'\n );\n }\n\n return <NavigationContent render={render}>{children}</NavigationContent>;\n }).current;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AASA,MAAMC,iBAAiB,GAAG,QAAiC;EAAA,IAAhC;IAAEC,MAAF;IAAUC;EAAV,CAAgC;EACzD,OAAOD,MAAM,CAACC,QAAD,CAAb;AACD,CAFD;;AAIA,eAAe,SAASC,YAAT,CAAsBF,MAAtB,EAAsC;EACnD,MAAMG,SAAS,GAAGL,KAAK,CAACM,MAAN,CAA4BJ,MAA5B,CAAlB,CADmD,CAGnD;EACA;EACA;;EACAG,SAAS,CAACE,OAAV,GAAoBL,MAApB;EAEAF,KAAK,CAACQ,SAAN,CAAgB,MAAM;IACpBH,SAAS,CAACE,OAAV,GAAoB,IAApB;EACD,CAFD;EAIA,OAAOP,KAAK,CAACM,MAAN,CAAa,SAAiD;IAAA,IAAhD;MAAEH;IAAF,CAAgD;IACnE,MAAMD,MAAM,GAAGG,SAAS,CAACE,OAAzB;;IAEA,IAAIL,MAAM,KAAK,IAAf,EAAqB;MACnB,MAAM,IAAIO,KAAJ,CACJ,+EADI,CAAN;IAGD;;IAED,oBAAO,oBAAC,iBAAD;MAAmB,MAAM,EAAEP;IAA3B,GAAoCC,QAApC,CAAP;EACD,CAVM,EAUJI,OAVH;AAWD"}
\No newline at end of file