Organize your code snippets
handy frontend snippets for everyday problems.
JJiordi Viera
1 snippets
Updated 5 days ago
Public
Public
A minimal example using SWR for client-side data fetching and caching.
javascript
import useSWR from 'swr';
const fetcher = (url) => fetch(url).then((res) => res.json());
export default function Posts() {
const { data, error } = useSWR('/api/posts', fetcher);
if (error) return <div>Failed to load</div>;
if (!data) return <div>Loading...</div>;
return (
<ul>
...
---