tests erster React Oberflächen Technik 2

This commit is contained in:
2026-07-29 21:31:50 +02:00
parent 0cc83a0c19
commit 3af4e19522
3 changed files with 25 additions and 11 deletions
+14 -6
View File
@@ -52,12 +52,20 @@
} }
} }
.sidebar h2 { .treeElement p {
font-size: 12px;
margin: 8px 16px 0 0;
}
.treeElement {
background: whitesmoke;
border-inline: 1px solid var(--border);
box-sizing: border-box;
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
}
.treeElement h2 {
font-size: 14px; font-size: 14px;
letter-spacing: -1px; letter-spacing: -1px;
margin: 8px 16px 0 0; margin: 4px 16px 0 0;
@media (max-width: 1024px) {
font-size: 14px;
margin: 20px 0;
}
} }
@@ -1,11 +1,16 @@
import { useState } from 'react' import { useState } from 'react'
//import UseFetch from './tools/UseFetch'; import UseFetch from './tools/UseFetch';
const Language = ({ languageid }) => { const Language = ({ languageid }) => {
const { data: lang, isLoading, error } = UseFetch(`http://localhost:8088/language/${languageid}`)
if (isLoading) return <p>Loading profile...</p>
if (error) return <p>Error: {error}</p>
return ( return (
<div className="treeElement"> <div className="treeElement">
<h2>Language ${languageid}</h2> <h2>Language: {lang.language}</h2>
<p>Locale: {lang.locale}</p>
</div> </div>
); );
} }
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
function UseFetch(url, options) { function UseFetch(url, options = {method: 'GET'}) {
const [data, setData] = useState(null) const [data, setData] = useState(null)
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState(null) const [error, setError] = useState(null)
@@ -20,7 +20,8 @@ function UseFetch(url, options) {
.then((json) => setData(json)) .then((json) => setData(json))
.catch((err) => setError(err.message)) .catch((err) => setError(err.message))
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
}) },[])
return { data, isLoading, error } return { data, isLoading, error }
} }