Skip to content

Commit

Permalink
Add cleanup to setFnrRef
Browse files Browse the repository at this point in the history
  • Loading branch information
tu55eladd committed Oct 6, 2023
1 parent fce260c commit 61ef0be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ export const useErVeileder = (): boolean => {
export const FnrContext = React.createContext<undefined | string>(undefined);
export const useFnr = () => useContext(FnrContext);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const noOp = (_: string | undefined) => {};
const Provider = ({ children, setFnrRef, fnr: propFnr }: Props) => {
const [fnr, setFnr] = useState(propFnr);
useEffect(() => {
if (setFnrRef) setFnrRef(setFnr);
return () => {
if (setFnrRef) {
setFnrRef(noOp);
}
};
}, []);

const store = useMemo(createStore, [fnr]);
Expand Down
2 changes: 1 addition & 1 deletion src/webcomponentWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DabAktivitetsplan extends HTMLElement {
const fnr = this.getAttribute('data-fnr') ?? undefined;
settLocalStorage(LocalStorageElement.FNR, fnr);
ReactDOM.render(
<ModalProvider appElement={appRoot} rootElement={shadowDomFirstChild}>
<ModalProvider rootElement={shadowDomFirstChild}>
<Provider key={fnr} fnr={fnr} setFnrRef={(setFnr) => (this.setFnr = setFnr)}>
<App Routes={Routes} key={'1'} />
</Provider>
Expand Down

0 comments on commit 61ef0be

Please sign in to comment.