feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s

This commit is contained in:
slawek committed 2026-11-14 12:52:44 +01:00
1 parent 6d90441bee
commit 8efe21bfa6
129 files changed
+17381 -104

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import { useCallback, useEffect, useState } from 'react'
/**
* What load answers, read at once and again by refresh: data, null until the first answer; error, the message of the
* last failure, null after a success; and busy while a read runs. load is read again whenever it changes, so it is
* kept stable, with useCallback where it depends on props.
*/
export function useRead<T>(load: () => Promise<T>) {
const [data, setData] = useState<T | null>(null)
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const refresh = useCallback(async () => {
setBusy(true)
try {
setData(await load())
setError(null)
} catch (caught) {
setError((caught as Error).message)
} finally {
setBusy(false)
}
}, [load])
useEffect(() => {
void refresh()
}, [refresh])
return { data, error, busy, refresh }
}