package-bottle.jsx edit to inlude loading

This commit is contained in:
Thomas Smith 2023-01-20 16:25:24 -05:00
parent 2be6f65817
commit 5de6a86c16

View file

@ -1,13 +1,19 @@
function PackageBottles() {
const [bottles, setBottles] = React.useState();
const [isLoading, setIsLoading] = React.useState(true);
React.useEffect(() => {
const url = window.location.pathname.replace('/+', 'https://app.tea.xyz/api/bottles/');
fetch(url)
.then((res) => res.json())
.then((res) => setBottles(res));
.then((res) => {
setBottles(res);
setIsLoading(false);
});
}, []);
if (isLoading) return <div>Loading...</div>;
if (!bottles) return null;
const names = [...new Set(bottles.map((b) => b.name))];