mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Caching fetched resources
This commit is contained in:
parent
7e93e41edc
commit
3daeef184a
12 changed files with 213 additions and 85 deletions
|
@ -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>
|
||||
</>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue