Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active August 30, 2022 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/d5d94dad94f3a82c9df3ff77464e7fcf to your computer and use it in GitHub Desktop.
Save NetanelBasal/d5d94dad94f3a82c9df3ff77464e7fcf to your computer and use it in GitHub Desktop.
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