inblog logo
|
qwerty

    TEST

    test
    Jul 25, 2023
    TEST
    ๐Ÿ”
    React frontend development framework created by Vercel that enables functionality such as SSR, SSG
     
    built on top of React(CSR based)
    โ†’ SSR: better SEO & performance
    โ†’ SSR์˜ ์žฅ์  + CSR์˜ ์žฅ์ (Quick, Dynamic client-side routing.. etc)
     
    ๋‹ค๋ฅธ ์žฅ์ ?
    • ์‰ฌ์šด ํŽ˜์ด์ง€ ๋ผ์šฐํŒ…(react-router-dom bye): pages ํด๋”์— ๋„ฃ์œผ๋ฉด ํŒŒ์ผ๋ช…์œผ๋กœ ๋ผ์šฐํŒ…๋จ
    • API Routes โ†’ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํŒŒ์ผ ๊ตฌ์กฐ๋กœ ๊ตฌํ˜„
    • TypeScript & Sass
    • SSG(next export)
    • Easy Deployment(vercel, github pages, .. ์ฃผ๋กœ ์—ฐ์Šตํ•  ๋•Œ..ใ…Žใ…‹)
     
    create-next-app
     
    stylesheet convention
    global css๋Š” ๊ฐœ๋ณ„ ์ปดํฌ๋„ŒํŠธ์— ๋”ฐ๋กœ ์ž„ํฌํŠธ ๋ถˆ๊ฐ€
    <Component Name>.module.css๋กœ ํ•˜์…ˆ(.module.css๋งŒ ์žˆ์œผ๋ฉด ๋จ)
     
    component/page filename convention
    pages์—๋Š” ์†Œ๋ฌธ์ž
    component๋Š” ๋Œ€๋ฌธ์ž
     
    /pages/_document
    : ํŽ˜์ด์ง€ ๋‚ด html ํƒœ๊ทธ ์ž์ฒด, body๋ฅผ ๊ฑด๋“œ๋ฆฌ๊ณ  ์‹ถ์„ ๋•Œ
    โ†’ ์„œ๋ฒ„์—์„œ ๋งŒ๋“ค์–ด์ ธ ๋‚˜์˜ค๋Š” ๊ฑฐ๋ผ ์ธํ„ฐ๋ž™์…˜ ์žˆ๋Š” ๊ฑด ๋ถˆ๊ฐ€
    https://nextjs.org/docs/advanced-features/custom-document
    <html lang="en"> โ€”> ์ผ์ผ€ ๋„ฃ๋Š”๊ฑฐ์ œ
     
    3๊ฐ€์ง€ methods to get data from server
    1. getStaticProps: ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ ๋‚ด์—์„œ ํ•จ๊ป˜ export ํ•ด๋‘๋ฉด ๋ Œ๋” ์ „์— ๋Œ์–ด์™€์„œ props์— ๋„ฃ์–ด์คŒ
    1. getServerSideProps: ๋ฐ์ดํ„ฐ ์†Œ์Šค๊ฐ€ ๊ฐ€๋ณ€์ ์ธ(ex. ๊ฒŒ์‹œ๊ธ€ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ.. ๊ธ€ id์— ๋”ฐ๋ผ ์†Œ์Šค ๋‹ฌ๋ผ์ง) fetching
    1. getStaticPath:
     
    nested routing
    :๋งŒ์•ฝ url์ด /post/:id๋ผ๋ฉด
    :ํด๋” ๊ตฌ์กฐ๋ฅผ pages/post/[id]/index.js ์ด๋ ‡๊ฒŒ ๊ฐ€์ ธ๊ฐ€๋ฉด the end.
    : param ์ฐพ๋Š” ๋ฒ•
    import {useRouter} from 'next/router'; const router = userRouter(); const {id} = router.query; // getServerSideProps, .. -> ์ธ์ˆ˜๋กœ context -> context.id ํ•ด์„œ ๊บผ๋ƒ„
     
    getStaticPaths()
    : dynamically generate paths (e.g. /posts/:id)
     
    /api ํด๋”์—์„œ /posts/[id].js ์ด๋Ÿฐ ๊ณณ์— api๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.
     
    Share article

    qwerty

    RSSยทPowered by Inblog