-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
프론트엔드 코드리뷰 #1
base: review
Are you sure you want to change the base?
프론트엔드 코드리뷰 #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전체적인 리뷰를 종합해보자면 다음과 같습니다.
- 고차 컴포넌트 활용하기
- state를 그대로 사용하기보단 구조분해할당을 이용하여 명시적으로 변수를 선언해보기
- useCallback을 이용하여 렌더링이 될 때 마다 동일한 함수가 선언되는 현상 방지하기
- 즉, 메모이제이션을 적극적으로 사용해보세요!
export default 변수명
형태로 export 해보기- 이렇게 해야 에디터나 IDE에서 auto import를 하거나 rename을 할 때 수월하답니다!
- 불필요한 catch문 제거하기
- catch에서 단순하게
throw error
를 하는 것은 의미가 없답니다! - 오류가 발생했을 때 후처리가 필요한 코드를 넣거나 아예 제거해도 무방합니다.
- catch에서 단순하게
- 적절하게 삼항연산자를 사용하는 것은 좋지만, 가독성을 항상 생각해주세요! 일부 코드는 삼항연사자 때문에 가독성이 무척 좋지 않은 상태입니다.
- 사용중인 패키지가
deprecated
되지 않는지 확인해보기- momentjs나 crypto 같은 경우 공식적으로 지원이 종료된 패키지입니다.
- 대체 패키지를 사용해보세요!
이 외에 상세한 내용은 리뷰 내용을 확인해보시면 좋을 것 같습니다 😁
수고하셨습니다!
console.error('Path:', err.path); | ||
console.error('Message:', err.message); | ||
console.error('Code:', err.extensions.code); | ||
console.error('Original Error', err.originalError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destructuring 해서 사용해보면 어떨까요?
|
||
module.exports = { | ||
development: { | ||
username: DB_DEV_USER, | ||
password: DB_DEV_PASSWORD, | ||
database: DB_DEV_DATABASE, | ||
host: DB_DEV_HOST, | ||
dialect: 'mysql', | ||
}, | ||
test: { | ||
username: DB_DEV_USER, | ||
password: DB_DEV_PASSWORD, | ||
database: DB_DEV_DATABASE, | ||
host: DB_DEV_HOST, | ||
dialect: 'mysql', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.exports = { | |
development: { | |
username: DB_DEV_USER, | |
password: DB_DEV_PASSWORD, | |
database: DB_DEV_DATABASE, | |
host: DB_DEV_HOST, | |
dialect: 'mysql', | |
}, | |
test: { | |
username: DB_DEV_USER, | |
password: DB_DEV_PASSWORD, | |
database: DB_DEV_DATABASE, | |
host: DB_DEV_HOST, | |
dialect: 'mysql', | |
}, | |
const DEV_ENV = { | |
username: DB_DEV_USER, | |
password: DB_DEV_PASSWORD, | |
database: DB_DEV_DATABASE, | |
host: DB_DEV_HOST, | |
dialect: 'mysql', | |
}; | |
module.exports = { | |
development: { ...DEV_ENV }, | |
test: { ...DEV_ENV }, |
이렇게 사용하면 확장하고 유지하기가 편리할 것 같아요!
|
||
fs.readdirSync(__dirname) | ||
.filter(file => { | ||
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'; | |
return !file.startWith('.') && file !== basename && file.endWith('.js'); |
이렇게 startWith
와 endWith
라는 메소드를 사용해도 된답니다!
Object.keys(db).forEach(modelName => { | ||
if (db[modelName].associate) { | ||
db[modelName].associate(db); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일단 Object.keys 대신에 values를 사용해보면 어떨까요?
Object.keys(db).forEach(modelName => { | |
if (db[modelName].associate) { | |
db[modelName].associate(db); | |
} | |
}); | |
Object.values(db) | |
.filter(model => model.associate) | |
.forEach(model => model.associate(db)); |
그리고 다음과 같이 optional channing
을 이용하는 방법도 있답니다!
Object.keys(db).forEach(modelName => { | |
if (db[modelName].associate) { | |
db[modelName].associate(db); | |
} | |
}); | |
Object.values(db).forEach(model => model.associate?.(db)); |
name: '개인실', | ||
}, | ||
{ | ||
name: '호텔 객실', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오타가 있네요!
import Modal from 'components/Modal'; | ||
import { isMobile } from 'Constants'; | ||
|
||
export default ({ name, modalBody, isClicked, setIsClicked, onClick }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앞선 리뷰를 참고해주세요!
> | ||
{name} | ||
</button> | ||
{!isMobile() && isClicked && <Modal body={modalBody} />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앞선 리뷰(고차 컴포넌트)를 참고해주세요!
const buttonModalBodyList = [ | ||
(buttonState, setButtonState) => <DateFilter buttonState={buttonState} setButtonState={setButtonState} />, | ||
(buttonState, setButtonState) => <PersonnelFilter buttonState={buttonState} setButtonState={setButtonState} />, | ||
(buttonState, setButtonState) => <PriceFilter buttonState={buttonState} setButtonState={setButtonState} />, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 함수 외부에서 선언해줘도 될 것 같아요!
const searchStates = buttonStateList.map((state, index) => { | ||
return { | ||
name: state[0].buttonName, | ||
modalBody: buttonModalBodyList[index](state[0], state[1]), | ||
isClicked: state[0].isClicked, | ||
setIsClicked: isClicked => { | ||
state[1]({ ...state[0], isClicked }); | ||
}, | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const searchStates = buttonStateList.map((state, index) => { | |
return { | |
name: state[0].buttonName, | |
modalBody: buttonModalBodyList[index](state[0], state[1]), | |
isClicked: state[0].isClicked, | |
setIsClicked: isClicked => { | |
state[1]({ ...state[0], isClicked }); | |
}, | |
}; | |
}); | |
const searchStates = buttonStateList.map((state, index) => ({ | |
name: state[0].buttonName, | |
modalBody: buttonModalBodyList[index](state[0], state[1]), | |
isClicked: state[0].isClicked, | |
setIsClicked: isClicked => { | |
state[1]({ ...state[0], isClicked }); | |
}, | |
})); |
이렇게 표현할 수 있답니다!
(buttonState, setButtonState) => <PriceFilter buttonState={buttonState} setButtonState={setButtonState} />, | ||
]; | ||
|
||
const searchStates = buttonStateList.map((state, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state를 분해하여 사용해보면 어떨가요?
No description provided.