diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2022-12-26 00:11:58 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2022-12-26 00:11:58 -0500 |
| commit | fd3e3280a2590be9ca074a172c535990a5035649 (patch) | |
| tree | 232f23010449a5aea88052c6e860a68ef9bdeb34 /paste-ui/src/list.js | |
| parent | 0704674ba408db54855c33bcb8ca71a7ae1e74b7 (diff) | |
| download | paste-fd3e3280a2590be9ca074a172c535990a5035649.tar.gz paste-fd3e3280a2590be9ca074a172c535990a5035649.tar.xz | |
Add a proxy option for static assets. Fix the paste view handlers.
Diffstat (limited to 'paste-ui/src/list.js')
| -rw-r--r-- | paste-ui/src/list.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/paste-ui/src/list.js b/paste-ui/src/list.js new file mode 100644 index 0000000..9371367 --- /dev/null +++ b/paste-ui/src/list.js @@ -0,0 +1,46 @@ +import { useState } from "react"; +import { useEffect } from "react"; + + +export default function List() { + const [error, setError] = useState(null); + const [isLoaded, setIsLoaded] = useState(false); + const [items, setItems] = useState([]); + + // Note: the empty deps array [] means + // this useEffect will run once + // similar to componentDidMount() + useEffect(() => { + fetch("http://localhost:6130/api/v1/list") + .then(res => res.json()) + .then( + (result) => { + setIsLoaded(true); + setItems(result); + }, + // Note: it's important to handle errors here + // instead of a catch() block so that we don't swallow + // exceptions from actual bugs in components. + (error) => { + setIsLoaded(true); + setError(error); + } + ) + }, []) + + if (error) { + return <div>Error: {error.message}</div>; + } else if (!isLoaded) { + return <div>Loading...</div>; + } else { + return ( + <ul> + {items.map(item => ( + <li> + ID: {item.id} Size: {item.size} + </li> + ))} + </ul> + ); + } +}
\ No newline at end of file |
