tests erster React Oberflächen Technik

This commit is contained in:
2026-07-28 22:39:29 +02:00
parent d78355d49e
commit 990cc0d5a7
27 changed files with 2056 additions and 3 deletions
@@ -0,0 +1,27 @@
import { useState, useEffect } from 'react'
function UseFetch(url, options) {
const [data, setData] = useState(null)
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState(null)
useEffect(() => {
console.log('UseFetch: useEffect called with url =', url, 'options =', options)
setIsLoading(true)
setError(null)
fetch(url, options)
.then((response) => {
if (!response.ok) {
console.log('UseFetch: response not ok, status =', response.status)
throw new Error(`HTTP error! status: ${response.status}`)
}
return response.json()
})
.then((json) => setData(json))
.catch((err) => setError(err.message))
.finally(() => setIsLoading(false))
})
return { data, isLoading, error }
}
export default UseFetch