fix: route home for missing problems
This commit is contained in:
+3
-3
@@ -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)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user