From b36cde771e68f5e01bca4440c69f2a1e16b7cdb0 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 11 Dec 2021 11:58:07 +0000 Subject: [PATCH] feat(mobx): expose application state to window --- src/redux/State.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/redux/State.tsx b/src/redux/State.tsx index 46474ab7..fddb34b2 100644 --- a/src/redux/State.tsx +++ b/src/redux/State.tsx @@ -1,7 +1,7 @@ import localForage from "localforage"; import { Provider } from "react-redux"; -import { useEffect, useState } from "preact/hooks"; +import { useEffect, useRef, useState } from "preact/hooks"; import MobXState, { StateContextProvider } from "../mobx/State"; @@ -18,7 +18,12 @@ interface Props { */ export default function StateLoader(props: Props) { const [loaded, setLoaded] = useState(false); - const [state] = useState(new MobXState()); + const { current: state } = useRef(new MobXState()); + + // Globally expose the application state. + useEffect(() => { + (window as unknown as Record).state = state; + }, [state]); useEffect(() => { localForage.getItem("state").then((state) => {