Skip to content

Commit

Permalink
Merge pull request #97 from EmploymentRescueTeam/feature/#94
Browse files Browse the repository at this point in the history
Feat: ssr test
  • Loading branch information
LeHiHo authored Nov 5, 2023
2 parents 1f8b1d4 + cfc78cf commit 2af0104
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/app/main/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import MainPage from '@/templates/main/mainPage';
import { getProducts } from '@/api/service';

export default async function Main() {
const data = await getProducts();

export default function Main() {
return (
<>
<MainPage />
<MainPage data={data} />
</>
);
}
23 changes: 4 additions & 19 deletions src/templates/main/mainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
'use client';

import { getProducts } from '@/api/service';
import Header from '@/components/header';
import ProductList from '@/components/productList';
import { AXIOSResponse, IProduct } from '@/types/interface';
import '@/styles/templates/main/main.scss';
import AddBtn from './addBtn';
import { AiOutlineSearch } from 'react-icons/ai';
import { RxHamburgerMenu } from 'react-icons/rx';
import Navbar from '@/components/navbar';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useSearchParams } from 'next/navigation';
interface MainPageProps {
data: any[]; // Use a more specific type based on your data structure
}

export default function MainPage() {
const [data, setData] = useState<IProduct[]>([]);
export default function MainPage({ data }: MainPageProps) {
const categoryParams = useSearchParams();
const category = categoryParams.get('category') || undefined;

const router = useRouter();

useEffect(() => {
const fetchData = async () => {
const res: AXIOSResponse<IProduct[]> = await getProducts(
undefined,
category,
);
if (res.statusCode === 200) {
setData(res.data);
}
};

fetchData();
}, [category]);

return (
<div id="mainPage">
<header>
Expand Down

0 comments on commit 2af0104

Please sign in to comment.