mirror of
https://github.com/revoltchat/revite.git
synced 2025-02-23 08:41:05 -05:00
28 lines
714 B
TypeScript
28 lines
714 B
TypeScript
import localForage from "localforage";
|
|
import { Provider } from "react-redux";
|
|
|
|
import { useEffect, useState } from "preact/hooks";
|
|
|
|
import { dispatch, State, store } from ".";
|
|
import { Children } from "../types/Preact";
|
|
|
|
interface Props {
|
|
children: Children;
|
|
}
|
|
|
|
export default function StateLoader(props: Props) {
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
useEffect(() => {
|
|
localForage.getItem("state").then((state) => {
|
|
if (state !== null) {
|
|
dispatch({ type: "__INIT", state: state as State });
|
|
}
|
|
|
|
setLoaded(true);
|
|
});
|
|
}, []);
|
|
|
|
if (!loaded) return null;
|
|
return <Provider store={store}>{props.children}</Provider>;
|
|
}
|