react.js의 라이브러리인 next.js에 대해 간단히 정리해보자
npm i create-next-app 디렉터리
<Link href="/photo">
<a>이동하기</a>
</Link>
//Photo.module.css
.container{ display:flex;}
// photo.js
import StylesPhoto from "../styles/Photo.module.css"
<div className={StylesPhoto.container]>ex</div>
//_app.js
import '../styles/global.css'
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
import Head from "next/head";
<Head>
<title>{title}</title>
<meta keyword={keyword} />
<meta content={content} />
</Head>
HeadInfo.defaultProps = {
title: "next exmple",
keyword: "next ex",
contents: "practice next js",
};
import Image from "next/image";
<Image
src={photo.thumbnailUrl}
width={100}
height={100}
alt={photo.title}
/>
//next.config
module.exports = {
images: {
domains: ['example.com'],
},
}
<Script
src="https://connect.facebook.net/en_US/sdk.js"
strategy="lazyOnload"
onLoad={() =>
console.log(`script loaded correctly, window.FB has been populated`)
}
/>
const postComponent = ({posts}) => {
return (
<ul>
{
posts.map(post => {
return <li>{post.title}</li>
})
}
</ul>
)
}
// 서버사이드 렌더링일때
export const getServerSideProps = async () => {
const res = await fetch(URL);
const posts = await res.json();
return {
props: {
posts: posts,
},
};
};
// 클라이언트 사이드 렌더링일때
export const getStaticProps = async () => {
const res = await fetch(URL);
const posts = await res.json();
return {
props: {
posts: posts,
},
revalidate: 10,
};
};