Skip to content
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

Open
wants to merge 20 commits into
base: review
Choose a base branch
from

Conversation

JunilHwang
Copy link

No description provided.

@JunilHwang JunilHwang changed the title [Web Frontend] [Frontend] 코드리뷰 Aug 15, 2021
@JunilHwang JunilHwang changed the title [Frontend] 코드리뷰 프론트엔드 코드리뷰 Aug 15, 2021
Copy link
Author

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적인 리뷰를 종합해보자면 다음과 같습니다.

  1. 고차 컴포넌트 활용하기
  2. state를 그대로 사용하기보단 구조분해할당을 이용하여 명시적으로 변수를 선언해보기
  3. useCallback을 이용하여 렌더링이 될 때 마다 동일한 함수가 선언되는 현상 방지하기
    • 즉, 메모이제이션을 적극적으로 사용해보세요!
  4. export default 변수명 형태로 export 해보기
    • 이렇게 해야 에디터나 IDE에서 auto import를 하거나 rename을 할 때 수월하답니다!
  5. 불필요한 catch문 제거하기
    • catch에서 단순하게 throw error를 하는 것은 의미가 없답니다!
    • 오류가 발생했을 때 후처리가 필요한 코드를 넣거나 아예 제거해도 무방합니다.
  6. 적절하게 삼항연산자를 사용하는 것은 좋지만, 가독성을 항상 생각해주세요! 일부 코드는 삼항연사자 때문에 가독성이 무척 좋지 않은 상태입니다.
  7. 사용중인 패키지가 deprecated 되지 않는지 확인해보기
    • momentjs나 crypto 같은 경우 공식적으로 지원이 종료된 패키지입니다.
    • 대체 패키지를 사용해보세요!

이 외에 상세한 내용은 리뷰 내용을 확인해보시면 좋을 것 같습니다 😁
수고하셨습니다!

Comment on lines +20 to +23
console.error('Path:', err.path);
console.error('Message:', err.message);
console.error('Code:', err.extensions.code);
console.error('Original Error', err.originalError);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructuring 해서 사용해보면 어떨까요?

Comment on lines +15 to +30

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',
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js';
return !file.startWith('.') && file !== basename && file.endWith('.js');

이렇게 startWithendWith라는 메소드를 사용해도 된답니다!

Comment on lines +28 to +32
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 Object.keys 대신에 values를 사용해보면 어떨까요?

Suggested change
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을 이용하는 방법도 있답니다!

Suggested change
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
Object.values(db).forEach(model => model.associate?.(db));

name: '개인실',
},
{
name: '호텔 객실',
Copy link
Author

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 }) => {
Copy link
Author

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} />}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앞선 리뷰(고차 컴포넌트)를 참고해주세요!

Comment on lines +17 to +21
const buttonModalBodyList = [
(buttonState, setButtonState) => <DateFilter buttonState={buttonState} setButtonState={setButtonState} />,
(buttonState, setButtonState) => <PersonnelFilter buttonState={buttonState} setButtonState={setButtonState} />,
(buttonState, setButtonState) => <PriceFilter buttonState={buttonState} setButtonState={setButtonState} />,
];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 함수 외부에서 선언해줘도 될 것 같아요!

Comment on lines +23 to +32
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 });
},
};
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state를 분해하여 사용해보면 어떨가요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants