Giter Site home page Giter Site logo

star-next's Introduction

Next.js λΏŒμ‹œκΈ° πŸ€“

React + Express.js + react-router-dom β˜… ~ Server Side Rendering ~ β˜…
정말 쉽닀! next! (level~ πŸ‘―β€β™€οΈ)

개발 ν™˜κ²½ μ„ΈνŒ… πŸ“

  • npx create-next-app@latest .
  • npm install next@12 (ν˜„μž¬λŠ” 13 λ²„μ „κΉŒμ§€ λ‚˜μ™”μœΌλ―€λ‘œ, 12 λ²„μ „μœΌλ‘œ κΉ”μž.)
  • npm run dev : 개발 ν™˜κ²½ μ‹€ν–‰
  • npm run build : .next λΌλŠ” 곳에 λΉŒλ“œ 파일 생성
  • npm run start : 배포된 파일 μ‹€ν–‰

μž₯점

  • 검색 엔진 μ΅œμ ν™” (SEO)
  • λͺ¨λ“  νŒŒμΌμ— reactλ₯Ό import ν•  ν•„μš”κ°€ μ—†λ‹€.

Pages πŸ“

  • react.js component λ₯Ό export ν•˜κ³  μžˆλŠ” νŒŒμΌμ„ pages 폴더 μ•ˆμ— λ‘κΈ°λ§Œ ν•˜λ©΄ next.js κ°€ 파일의 이름을 κ°€μ Έλ‹€κ°€ url 의 μ΄λ¦„μœΌλ‘œ μ“΄λ‹€.
  • μ€‘μš”ν•œ 건, pages ν΄λ”μ—μ„œ μœ μ €μ—κ²Œ 보여 μ£Όκ³  싢은 κ±Έ export default function 을 톡해 μ—°κ²°ν•΄ μ£ΌλŠ” κ²λ‹ˆλ .

Routing πŸ“

  • anchor νƒœκ·Έμ— hrefλ₯Ό λ„£μ–΄ μ£ΌλŠ” 것이 μ•„λ‹Œ, Link νƒœκ·Έ μ•ˆμ— hrefλ₯Ό λ„£μ–΄ μ€˜μ•Ό ν•©λ‹ˆλ‹€.
  • λΌμš°νŒ… μ‹œ μ›Ή μ‚¬μ΄νŠΈκ°€ μƒˆλ‘œκ³ μΉ¨ λ˜μ§€ μ•ŠλŠ” 큰 μž₯점이 μžˆμŠ΅λ‹ˆλ‹€.
  • style μ΄λ‚˜ className μ μš©μ‹œν‚¬ λ•ŒλŠ” Link > anchor νƒœκ·Έμ— μ μš©μ‹œν‚΅λ‹ˆλ‹€.

CSS Modules πŸ“

  • XXXX.module.css νŒŒμΌμ„ μƒμ„±ν•œλ‹€.
  • import styles from "./XXXX.module.css"
  • μžλ°”μŠ€ν¬λ¦½νŠΈ μ˜€λΈŒμ νŠΈμ—μ„œμ˜ ν”„λ‘œνΌν‹° ν˜•μ‹μœΌλ‘œ μ λŠ”λ‹€. (ex. className={styles.nav})
  • νŠΉμ • λ¬Έμžμ—΄μ„ λ§Œλ“€μ–΄μ„œ μ‚½μž…ν•˜λŠ” 방식도 μžˆλ‹€. (ex. <div className={${styles.link}} ${router.pathname === "/" ? styles.active : ""} )
  • 클래슀 μ΄λ¦„λ“€μ˜ 배열을 λ§Œλ“œλŠ” 방법도 μžˆλ‹€. (ex. <div className={[styles.link, router.pathname === "/about" ? styles.active : "",]join(" ")}>)

단점

  • μš”μ†Œλ³„λ‘œ νŒŒμΌμ„ λ°”κΏ”μ•Ό 함.
  • 클래슀 이름듀을 κΈ°μ–΅ν•΄μ•Ό ν•˜λŠ” 문제.
  • 클래슀 이름 자체λ₯Ό κ΅¬ν˜„ν•˜λŠ” 게 λ³΅μž‘μ‹œλ €μ›€, 특히 쑰건자....

Styles JSX πŸ“

  • NextJS 고유의 방법.
  • μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μ— styles λ₯Ό μΆ”κ°€ν•˜λŠ” 또 λ‹€λ₯Έ 방식이닀.
  • λ‚΄λΆ€ μŠ€νƒ€μΌ μ‹œνŠΈμ—μ„œ jsx props μΆ”κ°€ν•œ λ’€, μ€‘κ΄„ν˜Έλ‘œ 백틱을 감싸면 λœλ‹€.
  • μ»΄ν¬λ„ŒνŠΈ λ‚΄λΆ€ λ²”μœ„μ— ν•΄λ‹Ήλ˜λŠ” μ˜μ—­μ—μ„œλ§Œ μŠ€νƒ€μΌ 지정이 κ°€λŠ₯ν•˜λ‹€.

Custom App πŸ“

  • μ „μ—­ styles λ₯Ό μΆ”κ°€ν•˜κ³  싢을 λ•ŒλŠ” styls jsx 에 global prop 을 μΆ”κ°€ν•΄ μ€€λ‹€.
  • styles/global.css λŠ” App μ»΄ν¬λ„ŒνŠΈμ—μ„œλŠ” 적용이 λΆˆκ°€λŠ₯ν•˜κ³ , μ»€μŠ€ν…€λœ νŽ˜μ΄μ§€λ‚˜ μ»΄ν¬λ„ŒνŠΈ λ‚΄μ—μ„œλ§Œ import ν•΄μ„œ μ‚¬μš©ν•  수 μžˆλ‹€.

Server Side Rendering πŸ“

  • export function getServerSideProps() {}
  • μš”μ²­ν•  λ•Œλ§ˆλ‹€ HTML 이 μƒμ„±λ˜κΈ° λ•Œλ¬Έμ— 데이터가 계속 μ—…λ°μ΄νŠΈ λœλ‹€.
  • 데이터λ₯Ό μƒˆλ‘œ 받아와 νŽ˜μ΄μ§€κ°€ λ Œλ”λ§ λœλ‹€.
  • ν•΄λ‹Ή νŽ˜μ΄μ§€ μ‚¬μš©μžκ°€ μš”μ²­ μ‹œ, getServerSideProps λ₯Ό μ„  μ‹€ν–‰ ν›„, front κ°€ server 에 직접 μš”μ²­ν•˜μ—¬ 데이터λ₯Ό λ°›μ•„μ™€μ„œ page μ»΄ν¬λ„ŒνŠΈμ— 데이터λ₯Ό props 둜 μ „λ‹¬ν•˜μ—¬ λ Œλ”λ§ ν•œλ‹€.
  • getServerSideProps λŠ” 데이터가 계속 λ°”λ€ŒλŠ” νŽ˜μ΄μ§€μ— μ‚¬μš©ν•˜μž.

Dynamic Routes! πŸ“

  • /movies/all 경둜λ₯Ό λ§Œλ“€κ³  μ‹Άλ‹€?

movies 폴더 생성 ν›„ > all μ»΄ν¬λ„ŒνŠΈ νŒŒμΌμ„ μΆ”κ°€ν•΄ μ£Όλ©΄ λœλ‹€.
movies 폴더 μ•ˆμ— μžˆλŠ” νŒŒμΌλ“€μ΄ μ•„λ¦„λ‹΅κ²Œ 맡핑될 것~

  • νŽ˜μ΄μ§€κ°€ ν•˜λ‚˜λΌλ©΄ 폴더λ₯Ό λ§Œλ“€μ–΄ 쀄 ν•„μš”λŠ” μ—†λ‹€.
  • URL 에 λ³€μˆ˜λ₯Ό λ„£λŠ” 방법

λŒ€κ΄„ν˜Έ μ•ˆμ— λ³€μˆ˜λͺ…을 적어 νŒŒμΌμ„ μƒμ„±ν•œλ‹€. (ex. [movieID].tsx)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.