mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
feat(mobx): expose application state to window
This commit is contained in:
parent
87a9841885
commit
b36cde771e
1 changed files with 7 additions and 2 deletions
|
@ -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) => {
|
||||||
|
|
Loading…
Reference in a new issue