Skip to content

Instantly share code, notes, and snippets.

@santhosh-chinnasamy
Created November 3, 2021 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santhosh-chinnasamy/a395e86a95aea371e879f4a43b318499 to your computer and use it in GitHub Desktop.
Save santhosh-chinnasamy/a395e86a95aea371e879f4a43b318499 to your computer and use it in GitHub Desktop.
import React from "react";
import { useQuery } from "react-query";
import axios from "axios";
import User from "./User";
export default function Users() {
const fetchUsers = async () => {
const response = await axios.get(
`https://gorest.co.in/public/v1/users?page=66`
);
return response.data;
};
const { data, isLoading, error, isError } = useQuery("users", fetchUsers, {
refetchOnWindowFocus: false,
});
if (isLoading) return <p>Loading...</p>;
if (isError) return <p>Error {error.message}</p>;
return (
<div className="container">
<User />
<h1>Users</h1>
<table>
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Status</th>
</tr>
{data?.data?.map((user) => {
return (
<tr key={user.id}>
<td>{user.id} </td>
<td>{user.name} </td>
<td>{user.email} </td>
<td>{user.status} </td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment