Preloader added to bottles.jsx

This commit is contained in:
Thomas Smith 2023-01-19 13:36:42 -05:00
parent f737eeff10
commit ef74d4fc00

View file

@ -1,12 +1,17 @@
function Bottles() {
const [bottles, setBottles] = React.useState();
const [isLoading, setLoading] = React.useState(true);
React.useEffect(() => {
fetch("https://app.tea.xyz/api/bottles")
.then((res) => res.json())
.then((res) => setBottles(res));
.then((res) => {
setBottles(res);
setLoading(false);
});
}, []);
if (isLoading) return <p>Loading...</p>;
if (!bottles) return null;
const names = [...new Set(bottles.map((b) => b.name))];