Like TailwindCSS, but for fetch(). className your way to API data!
npm install @tailwind-stack/fetch
import { Fetch } from "@tailwind-stack/fetch";
<Fetch className="fetch-[https://api.example.com/users/1]-select-name" />;
fetch-[url]-select-path.to.data
| Part |
Description |
fetch-[url] |
The URL to fetch |
-select-path |
Dot notation selector |
as prop |
Render format |
| Component |
Type |
Description |
Fetch |
Server (RSC) |
Fetches on server, zero client JS |
FetchClient |
Client |
Fetches in browser with loading state |
// Basic fetch with selector
<Fetch className="fetch-[https://jsonplaceholder.typicode.com/posts/1]-select-title" />
// Table render
<Fetch className="fetch-[https://api.example.com/users]" as="table" />
// JSON display
<Fetch className="fetch-[https://api.example.com/data]" as="json" />
// Array index selector
<Fetch className="fetch-[.../comments]-select-0.body" />
// Client component with loader
<FetchClient className="fetch-[url]" loader={<Spinner />} />
import { setConfig } from '@tailwind-stack/fetch'
setConfig({
aliases: {
jp: 'https://jsonplaceholder.typicode.com',
api: 'https://api.example.com',
},
})
// Use with $ prefix
<Fetch className="fetch-[$jp/users/1]" />
Pass data to children with $$response:
<Fetch className="fetch-[.../users/1]">
<QR className="qr-encode-[$$response.website]" />
</Fetch>
<Fetch className="fetch-[.../users/1]">
<span className="font-bold $$response.name" />
</Fetch>
| Token |
Result |
$$response |
Full response |
$$response.name |
Nested property |
$$response.users[0].id |
Array access |
| Format |
Output |
span |
Default text |
div |
Block element |
ul / ol |
List |
table |
HTML table |
json / code |
JSON block |
| Prop |
Type |
Default |
Description |
className |
string |
- |
Fetch directive |
as |
RenderAs |
"span" |
Render format |
style |
CSSProperties |
- |
Inline styles |
loader |
ReactNode |
- |
Loading state (FetchClient) |
children |
ReactNode |
- |
With $$response tokens |
MIT