Open MinJeung-Kim opened 1 year ago
'use client'; // Error components must be Client Components
import { useEffect } from 'react';
export default function Error({ error, reset, }: { error: Error; reset: () => void; }) { useEffect(() => { // Log the error to an error reporting service console.error(error); }, [error]);
return (
); }
### 중첩된 레이아웃에서 Error
- 만약 dashboard폴더에 error.js가 없다면 상위 error.js를 보여줌.
![image](https://github.com/MinJeung-Kim/NextJS-v13--Study/assets/79193369/929853f8-2616-4bbc-a72d-bccde9e2af63)
<Image />
태그Layout Shift
가 일어나지 않음. priority
: 이미지의 우선순위 지정import MeowArticle from "@/components/MeowArticle";
import { getProducts } from "@/service/products";
import Image from "next/image";
import clothesImage from "public/images/clothes.jpg";
export default async function ProductsPage() {
return (
{/* 경로보다는 로컬에 있으므로 Static하게 import하는게 좋음. */}
<Image src={clothesImage} alt="Clothes" />
);
}
사이즈 압축
스크린 사이즈별 이미지 최적화.
width
, height
지정.next.config.js
설정
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [{ protocol: "https", hostname: "images.unsplash.com" }],
},
};
module.exports = nextConfig;
next/font
는 자동으로 self-hosting 됨.size-adjust
라는 속성을 사용하 Layout Shift가 발생하지 않음.// app/layout.tsx
import { Open_Sans } from "next/font/google";
import { Nanum_Gothic } from "next/font/google";
const sans = Open_Sans({ subsets: ["latin"] });
const gothic = Nanum_Gothic({
weight: "700",
subsets: ["latin"],
});
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en" className={sans.className}>
<body>
<header className={styles.header}>
<h1 className={gothic.className}>Demo Note</h1>
</header>
{children}
</body>
</html>
);
}
⏳Loading UI
전체 페이지 로딩UI
export default function ProductsLoading() {
return
로딩중 입니다...⏳
; }<Suspense fallback={