Skip to content
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

[feat] 헤더 레이아웃 작업 #14

Merged
merged 5 commits into from
Aug 13, 2024
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
Empty file removed src/components/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions src/components/Layout/HeaderLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ReactNode } from "react";

interface HeaderLayoutProps {
children: ReactNode;
}

function HeaderLayout({ children }: HeaderLayoutProps) {
return (
<>
<header>추후 헤더 완성되면 만들어진 헤더 사용 예정 </header>
{children}
</>
);
}

export default HeaderLayout;
17 changes: 14 additions & 3 deletions src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import type { AppProps } from "next/app";
import { NextPage } from "next/types";

import { useState } from "react";
import { ReactElement, ReactNode, useState } from "react";

import { Global } from "@emotion/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

import reset from "@/styles/reset";

export default function App({ Component, pageProps }: AppProps) {
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
};

interface AppPropsWithLayout extends AppProps {
Component: NextPageWithLayout; // components 속성이 NextPageWithLayout 타입을 따르도록 변경
}

export default function App({ Component, pageProps }: AppPropsWithLayout) {
const [queryClient] = useState(
() =>
new QueryClient({
Expand All @@ -22,10 +31,12 @@ export default function App({ Component, pageProps }: AppProps) {
}),
);

const getLayout = Component.getLayout ?? ((page) => page);

return (
<QueryClientProvider client={queryClient}>
<Global styles={reset} />
<Component {...pageProps} />
{getLayout(<Component {...pageProps} />)}
Comment on lines -28 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Component가 페이지 기본 구조대로 렌더링 되는것(어떤 레이아웃이든지 상관없이 페이지 컴포넌트만 렌더링) 되는 방식에서 getLayout을 통한 렌더링으로 바꿔주셨네요 !! 유지보수까지 고려한 코드 LGTM입니다 !! 👍

</QueryClientProvider>
);
}