Caching fetched resources

This commit is contained in:
mrfry 2021-06-09 09:48:31 +02:00
parent 7e93e41edc
commit 3daeef184a
12 changed files with 213 additions and 85 deletions

View file

@ -10,6 +10,7 @@ function MyApp({ Component, pageProps, router }) {
const [userId, setUserId] = useState()
const [motd, setMotd] = useState()
const [unreads, setUnreads] = useState()
const [globalState, setGlobalState] = useState({})
const getGlobalProps = () => {
fetch(`${constants.apiUrl}infos?motd=true`, {
@ -50,6 +51,13 @@ function MyApp({ Component, pageProps, router }) {
getGlobalProps()
}, [])
const updateGlobalState = (newState) => {
setGlobalState({
...globalState,
...newState,
})
}
const globalData = {
userId: userId,
motd: motd,
@ -65,12 +73,16 @@ function MyApp({ Component, pageProps, router }) {
router={router}
globalData={globalData}
refetchGlobalData={getGlobalProps}
setGlobalState={updateGlobalState}
globalState={globalState}
>
<Component
{...pageProps}
router={router}
globalData={globalData}
refetchGlobalData={getGlobalProps}
setGlobalState={updateGlobalState}
globalState={globalState}
/>
</Layout>
</>