UNPKG

use-minimal-fetch

Version:

A lightweight useFetch hook with Axios wrapper for React apps

11 lines (10 loc) 625 B
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useFetchHook } from "../hooks/useFetchHook"; export default function Users() { const { data, loading, error, refetch } = useFetchHook("/forum/users/"); if (loading) return _jsx("p", { children: "Loading users..." }); if (error) return _jsxs("p", { children: ["Error: ", error.message] }); return (_jsxs("div", { children: [_jsx("h2", { children: "Users" }), _jsx("button", { onClick: refetch, children: "Refetch" }), _jsx("ul", { children: data?.map((user) => (_jsx("li", { children: user.email }, user.id))) })] })); }