fix: missing problem redirects to homepage
This commit is contained in:
+4
-2
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user