feat(mobx): expose application state to window

This commit is contained in:
Paul 2021-12-11 11:58:07 +00:00
parent 87a9841885
commit b36cde771e

View file

@ -1,7 +1,7 @@
import localForage from "localforage"; import localForage from "localforage";
import { Provider } from "react-redux"; import { Provider } from "react-redux";
import { useEffect, useState } from "preact/hooks"; import { useEffect, useRef, useState } from "preact/hooks";
import MobXState, { StateContextProvider } from "../mobx/State"; import MobXState, { StateContextProvider } from "../mobx/State";
@ -18,7 +18,12 @@ interface Props {
*/ */
export default function StateLoader(props: Props) { export default function StateLoader(props: Props) {
const [loaded, setLoaded] = useState(false); 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<string, unknown>).state = state;
}, [state]);
useEffect(() => { useEffect(() => {
localForage.getItem("state").then((state) => { localForage.getItem("state").then((state) => {