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

@ -22,13 +22,20 @@ function fetchSupportedSites() {
})
}
export default function Script() {
export default function Script({ globalState, setGlobalState }) {
const [supportedSites, setSupportedSites] = useState()
useEffect(() => {
fetchSupportedSites().then((res) => {
setSupportedSites(res)
})
if (globalState.supportedSites) {
setSupportedSites(globalState.supportedSites)
} else {
fetchSupportedSites().then((res) => {
setSupportedSites(res)
setGlobalState({
supportedSites: res,
})
})
}
}, [])
return (