mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-08 01:45:28 +00:00
Add Redux and reducers.
Load i18n files and add dayjs.
This commit is contained in:
32
src/redux/State.tsx
Normal file
32
src/redux/State.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { store } from ".";
|
||||
import localForage from "localforage";
|
||||
import { Provider } from 'react-redux';
|
||||
import { Children } from "../types/Preact";
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
async function loadState() {
|
||||
const state = await localForage.getItem("state");
|
||||
if (state) {
|
||||
store.dispatch({ type: "__INIT", state });
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
children: Children
|
||||
}
|
||||
|
||||
export default function State(props: Props) {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadState().then(() => setLoaded(true));
|
||||
}, []);
|
||||
|
||||
if (!loaded) return null;
|
||||
|
||||
return (
|
||||
<Provider store={store}>
|
||||
{ props.children }
|
||||
</Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user