ERROR
eslint 오류: Expected property shorthand eslint(object-shorthand)
로맨틱스터디
2023. 1. 31. 12:44
728x90
반응형
발단
클래스 컴포넌트에서 board state를 같은 board로 변경해주는 커스텀 메서드를 선언하는 부분에서 eslint 에러 발생
this.state = {
board: [],
}
getDetail = () => {
this.setState({
board: board,
});
}
에러 메시지
ES6 문법에서 좀 더 간단하게 표현할 수 있는 문법이 생겼다. 그걸 써라는 말임.
Expected property shorthand eslint(object-shorthand)
// es5
var foo = {
x: x,
y: y,
z: z,
};
// es6
var foo = { x, y, z };
// es5
var foo = {
a: function() {},
b: function() {}
};
// es6
var foo = {
a() {},
b() {}
};
해결
board: board를 -> board 한 단어로 축약해주면 간단하게 해결
this.setState({
board,
});
728x90
반응형