Skip to content

Code Convention | Frontend

Kyu-hyun Lee edited this page Aug 23, 2023 · 4 revisions

๐Ÿงน Prettier && Eslint Rules

  • ์ฝ”๋“œ์˜ ์ผ๊ด€์„ฑ์„ ์œ„ํ•ด Prettier์™€ ESLint ๊ทœ์น™์„ ์—„๊ฒฉํžˆ ์ค€์ˆ˜. ๊ฐ€๋Šฅํ•œ ๊ทœ์น™์„ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ ์˜ˆ์™ธ๋ฅผ ๋งŒ๋“ค์ง€ ์•Š๋„๋ก ํ•œ๋‹ค.

๐Ÿ— Component Structure

  • ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, ์ปดํฌ๋„ŒํŠธ ์„ ์–ธ ํ›„ ๋ณ€์ˆ˜, ํ•จ์ˆ˜, useEffect, return ๋ฌธ์„ ์ˆœ์„œ๋Œ€๋กœ ์ž‘์„ฑ.

๐Ÿท๏ธ Naming Conventions

๐Ÿ” Temporary Variables

  • ์ž„์‹œ ๋ณ€์ˆ˜๋ช…์€ ๋ณ€์ˆ˜์˜ ์šฉ๋„๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋„๋ก ์ž‘๋ช…ํ•˜๋ฉฐ, ํ•œ ๋ฌธ์ž ๋ณ€์ˆ˜๋ช…์€ ํ”ผํ•œ๋‹ค.

๐Ÿ”„ Array Destructuring (State ์„ ์–ธ)

  • ๋ฐฐ์—ด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น(Destructuring)์„ ์‚ฌ์šฉํ•˜์—ฌ state๋ฅผ ์„ ์–ธํ•  ๋•Œ ๋ชจ๋“  ์•„์ดํ…œ์€ camelCase๋กœ ์ž‘์„ฑํ•˜๊ณ , setter ํ•จ์ˆ˜ ์•ž์— "set"์„ ๋ถ™์—ฌ ์ž‘์„ฑ.
const [projectId, setProjectId] = useState<number>(0);

๐Ÿ“‚ File Structure and Folder Naming

  • ํ”„๋กœ์ ํŠธ ๋‚ด ํŒŒ์ผ๊ณผ ํด๋”๋Š” ์˜๋ฏธ ์žˆ๋Š” ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ทธ๋ฃนํ™”.
  • ์ปดํฌ๋„ŒํŠธ, ์Šคํƒ€์ผ, ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜ ๋“ฑ์„ ์ ์ ˆํ•˜๊ฒŒ ๊ตฌ๋ถ„ํ•˜์—ฌ ๋ฐฐ์น˜.
  • ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ์€ ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์˜ ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•˜๋„๋ก ํŒŒ์ผ ์ด๋ฆ„์„ ์ง€์ •.
  • ๋ฆฌ์†Œ์Šค ํŒŒ์ผ (์ด๋ฏธ์ง€, ํฐํŠธ ๋“ฑ)์€ assets ๋˜๋Š” static ํด๋”์— ์ €์žฅํ•˜์—ฌ ๊ด€๋ฆฌ.

๐Ÿ“š Type Definitions

  • ์ปค์Šคํ…€ ํƒ€์ž…์€ interface ๋Œ€์‹  type ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉฐ, ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ์—๋Š” interface ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉ.
type FollowModalProps = {
  onClickToggleModal: () => void;
  isFollowing: number;
};

โœ‰๏ธ Props Handling

  • props๋Š” ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น(Destructuring)์„ ํ†ตํ•ด ๋‹ค๋ฃจ๋ฉฐ, ์ปค์Šคํ…€ ํƒ€์ž… ์ด๋ฆ„์€ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„ ๋’ค์— "Props"๋ฅผ ๋ถ™์—ฌ ์ž‘์„ฑ.
function followModal({ onClickToggleModal, isFollowing }: FollowModalProps) { ... }

โš™๏ธ API Calls and Asynchronous Operations

  • API ํ˜ธ์ถœ ์‹œ async/await ๊ตฌ๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ.
async function main() {
  try {
    const userId = 1;
    const userInfo = await getUserInfo(userId);
    console.log('์‚ฌ์šฉ์ž ์ •๋ณด:', userInfo);
  } catch (error) {
    console.error('๋ฉ”์ธ ํ•จ์ˆ˜ ์‹คํ–‰ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:', error);
  }
}

โš ๏ธ Warning and Error Handling

  • ๋ธŒ๋ผ์šฐ์ € ์ฝ˜์†”์— ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ๊ณ ์™€ ์˜ค๋ฅ˜๋ฅผ ์ตœ์†Œํ™”ํ•˜๋ฉฐ, ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ๊ณ ๋ฅผ ์ฒ˜๋ฆฌ.
  • ๋ฐฐํฌ ํ™˜๊ฒฝ์—์„œ๋Š” ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•˜๊ฑฐ๋‚˜ ๊ฒฝ๊ณ ๋ฅผ ๋ฌด์‹œํ•˜๋„๋ก ์„ค์ •ํ•˜์—ฌ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ์ตœ์ ํ™”.