HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
♥️
2기 최종 프로젝트 팀별 공간
/
👩‍👩‍👦‍👦
[팀01] 김팽박이
/
2️⃣
Code Convention
2️⃣

Code Convention

Code ConventionNamingComponents Folder & NamingComponentsStylingFunctionsImport OrderAPI UsageStyle

Code Convention


Naming

📌
축약어를 사용하지 않고 작성한다. → ❌ btn ✅ button

Components Folder & Naming

┣ 📂components ┃ index.ts ┣ 📂HomePage ┃ ┣ 📂Button(component) ┃ ┃ ┣ Button.tsx ┃ ┃ ┣ Button.style.ts // Style 파일은 * 대신 named로 가져올 것 ┃ ┃ ┗ Button.stories.js

Components

// Button.tsx function Button() { return ( // ... ) } export default Button // index.ts export { default as Button } from './Button/Button'

Styling

// Button.style.ts import styled from '@emotion/styled' export const CustomButton = styled.button`` // Button.tsx import { CustomButton } from './Button.style' export function Button() { return ( <CustomButton >click me!</CustomButton> ) }

Functions

function Button() { const onClick = () => { //... } }
 

Import Order

  1. 리액트
  1. 라이브러리
  1. 모듈
  1. 스타일
// 리액트 import { useState, useEffect, ... } from 'react' // 라이브러리 import { throttle, debounce, ... } from "lodash"; // 모듈 // components, hooks, store, utils, assets, interface.. import { Button } from 'components' // 스타일 import { ButtonStyle } from './Button.style';
 

API Usage

// axiosInstance.ts import axios, { AxiosInstance } from 'axios'; const host = process.env.REACT_APP_API_HOST ?? 'localhost'; const port = process.env.REACT_APP_API_PORT ?? 3000; const API_ENDPOINT = `${host}:${port}`; const axiosInstance: AxiosInstance = axios.create({ baseURL: API_ENDPOINT, // baseURL 미리세팅 timeout: 5000, headers: { 'Content-Type': 'application/json', }, }); axiosInstance.interceptors.response.use( (response) => Promise.resolve(response), (error) => { console.error(error); return Promise.reject(error); }, ); export default axiosInstance;
// api/getPost.ts export const getPost = async (postId) => { const result = await axiosInstance({ method: 'GET', url: `/posts/${postId}` }) return result.data; };

Prettier

{ "endOfLine": "auto", "printWidth": 80, "semi": true, "singleQuote": true, "tabWidth": 2, "trailingComma": "all" }

Lint

- typescript/recommended - react
 

Style

font, spacing: rem 사용