Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import HomePage from "./pages/Home";

function App() {
return (
<HomePage />
<div>
<HomePage />
</div>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { http, HttpResponse } from "msw";

/* handlers: what ever request you want to mock you need an handler. interception */
export const handlers = [
http.get("/resource", ({ request }) => {
http.get("/api/users", ({ request }) => {
return HttpResponse.json([
{ id: 1, name: "John Doe", email: "johndoe@gmail.com" },
{ id: 2, name: "Smith Williams", email: "smithwilliams@gmail.com" },
Expand Down
28 changes: 28 additions & 0 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { motion } from "framer-motion";
import { useEffect, useState } from "react";
import { Link } from "react-router";

interface User {
id: number;
name: string;
email: string;
}

const HomePage = () => {
const [users, setUsers] = useState<User[]>([]);

useEffect(() => {
fetch("/api/users")
.then((response) => response.json())
.then((data) => setUsers(data))
.catch((error) => {
console.error(error);
});
}, []);

return (
<div className="h-screen w-full flex flex-col justify-center items-center">
<motion.h1
Expand All @@ -25,6 +43,16 @@ const HomePage = () => {
>
Learn more
</Link>
<div className="mt-8">
<h3 className="mb-4">Mock Service Worker Example:</h3>
<ul className="flex flex-col gap-2">
{users.map((user) => (
<li key={user.id}>
{user.name} | {user.email}
</li>
))}
</ul>
</div>
</div>
);
};
Expand Down