Last active
August 30, 2022 06:02
-
-
Save NetanelBasal/d5d94dad94f3a82c9df3ff77464e7fcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injector } from '@angular/core'; | |
import { PropsWithChildren, createContext, useContext } from 'react'; | |
import { createRoot, Root } from 'react-dom/client' | |
const InjectorCtx = createContext<Injector | null>(null) | |
export function NgContext(props: PropsWithChildren<{ injector: Injector }>) { | |
return createElement(InjectorCtx.Provider, { | |
children: props.children, | |
value: props.injector | |
}) | |
} | |
function useInjector(): Injector { | |
const injector = useContext(InjectorCtx); | |
if (!injector) { | |
throw new Error('Missing NgContext') | |
} | |
return injector; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment