-
Notifications
You must be signed in to change notification settings - Fork 5
Ticket 116 - mockup for API call #386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const baseUrl: string = 'https://63d006cc8a780ae6e681fea9.mockapi.io/api/members'; | ||
|
||
export interface Member { | ||
firstName: any; | ||
lastName: string; | ||
description: string; | ||
favoriteFruit: string; | ||
} | ||
|
||
export const MembersApi = { | ||
getMembers: async (): Promise<Member[]> => { | ||
const response = await fetch(baseUrl); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch members data'); | ||
} | ||
return response.json(); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
'use client' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) This means the whole may be rendered in the client. Alternatively the members list could be a client component that the page uses so the page could still be rendered server side. |
||
|
||
import { Member, MembersApi } from "src/api/MembersApi"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
export default function Page() { | ||
return <>healthy</>; | ||
const [members, setMembers] = useState<Member[]>([]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to have an error and loading states. |
||
|
||
const getMembers = async () => { | ||
try { | ||
const members = await MembersApi.getMembers(); | ||
setMembers(members); | ||
console.log(members); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getMembers(); | ||
}, []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getMembers should be a dependency |
||
|
||
return ( | ||
<React.Fragment> | ||
<h1>Members</h1> | ||
<ul> | ||
{members.map((member, index) => ( | ||
<li key={index}> | ||
<h2>{member.lastName}</h2> | ||
<p>{member.description}</p> | ||
<p>Favorite fruit: {member.favoriteFruit}</p> | ||
</li> | ||
))} | ||
</ul> | ||
</React.Fragment> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) The "health" page is often used to make sure the application is working, think we still use that on grants.gov https://github.com/HHS/simpler-grants-gov/blob/main/frontend/src/app/%5Blocale%5D/health/page.tsx . I would recommend keeping it as is and creating a separate page for this.