Skip to content

Commit

Permalink
fix: useFetch hook cannot handle two api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
moonbamijam committed Feb 12, 2024
1 parent ac46bdf commit bbde07a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/api/abouts/[id]/route.ts → app/api/about/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ export async function PUT(request: Request, { params }: Params) {
export async function GET(request: Request, { params }: Params ) {
const { id } = params;
await connectMongoDB();
const abouts = await About.findOne({ _id: id });
return NextResponse.json({ abouts }, { status: 200 });
const about = await About.findOne({ _id: id });
return NextResponse.json({ about }, { status: 200 });
};
4 changes: 2 additions & 2 deletions app/api/abouts/route.ts → app/api/about/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ export async function POST(request: Request, response: Response) {

export async function GET() {
await connectMongoDB();
const abouts = await About.find();
return NextResponse.json({ abouts })
const about = await About.find();
return NextResponse.json({ about })
};
17 changes: 13 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ import About from '@components/about/About';
import { TopicType } from '@customs/topic';
import { AboutType } from '@customs/about';

const handleTopics = async () => {
const data = await useFetch("/api/topics");
return data;
}
const handleAboutMe = async () => {
const data = await useFetch("/api/about");
return data;
}

const Home = async () => {
const { topics } = await useFetch("/api/topics")
// const { abouts } = await useFetch("/api/abouts")
const { topics } = await handleTopics()
const { about } = await handleAboutMe()
return (
<>
<Image priority src={ AkaneDream } alt="" id="home-bg" width={'3000'} height={'3000'} className="w-full h-[930px] object-cover absolute z-[-100] opacity-[0.5] dark:opacity-[0.3] " />
Expand All @@ -51,7 +60,7 @@ const Home = async () => {
<div className="about-me w-full flex flex-col lg:flex-row justify-between items-center lg:items-start 2xl:justify-evenly ">
<TopicImage src={ Me } />
<div className="about-me flex flex-col gap-[30px] ">
{/* {abouts.map((about: AboutType) => (
{about.map((about: AboutType) => (
<About
key={ about._id }
displayName={ about.displayName }
Expand All @@ -64,7 +73,7 @@ const Home = async () => {
nationality={ about.nationality }
status={ about.status }
languages={ about.languages }/>
))} */}
))}
</div>
</div>
<div className="topics w-full grid grid-cols-1 lg:grid-cols-2 gap-10 ">
Expand Down

0 comments on commit bbde07a

Please sign in to comment.