fix: missing problem redirects to homepage

This commit is contained in:
2022-11-24 19:38:25 +01:00
parent 702e40ad05
commit 438ddc8dd7
2 changed files with 16 additions and 7 deletions
+4 -2
View File
@@ -39,10 +39,11 @@ type HeuristicStateUpdater<S> = StateUpdater<S>
type ResourceHookFunction = <T>(
url: string | (() => string),
initialValue: T
initialValue: T,
onError?: () => void
) => [T, RefreshFunction, HeuristicStateUpdater<T>]
export const useResource: ResourceHookFunction = (url, initialValue) => {
export const useResource: ResourceHookFunction = (url, initialValue, onError) => {
const [value, setValue] = useState(initialValue)
function refresh() {
@@ -54,6 +55,7 @@ export const useResource: ResourceHookFunction = (url, initialValue) => {
if (res.ok) {
return res.json()
} else {
onError?.()
return initialValue
}
})