fix: route home for missing problems

This commit is contained in:
2022-11-24 20:01:31 +01:00
parent 438ddc8dd7
commit 717c2125c1
2 changed files with 9 additions and 11 deletions
+3 -3
View File
@@ -40,10 +40,10 @@ type HeuristicStateUpdater<S> = StateUpdater<S>
type ResourceHookFunction = <T>(
url: string | (() => string),
initialValue: T,
onError?: () => void
onValue?: (value: T) => void
) => [T, RefreshFunction, HeuristicStateUpdater<T>]
export const useResource: ResourceHookFunction = (url, initialValue, onError) => {
export const useResource: ResourceHookFunction = (url, initialValue, onValue) => {
const [value, setValue] = useState(initialValue)
function refresh() {
@@ -55,11 +55,11 @@ export const useResource: ResourceHookFunction = (url, initialValue, onError) =>
if (res.ok) {
return res.json()
} else {
onError?.()
return initialValue
}
})
.then(newValue => {
onValue?.(newValue)
setValue(newValue)
})