728x90 반응형 error4 ESLint error: Unnecessary 'else' after 'return'. 에러 메시지 Unnecessary 'else' after 'return'. 코드 vanilla redux에서 reducer 선언하는 중 action의 조건문에서 발생 const countModifier = (count = 0, action) => { console.log(count, action); if (action.type === "ADD") { return count + 1; } else if (action.type === "MINUS") { return count - 1; } return count; }; 해결법 else if문 대신 -> if문 사용 const countModifier = (count = 0, action) => { console.log(count, action); if (act.. 2023. 2. 27. ESlint error: Default parameters should be last. 에러 메시지 Default parameters should be last. 코드 vanilla redux에서 reducer를 선언하는 중 발생 const countModifier = (count = 0, action) => { console.log(count, action); if (action.type === "ADD") { return count + 1; } else if (action.type === "MINUS") { return count - 1; } return count; }; 해결법 https://eslint.org/docs/latest/rules/default-param-last 에는 default paremeter는 무조건 마지막에 넣어주라고 되어있었다. const countModifi.. 2023. 2. 27. ESLint Error: Assignment (=) can be replaced with operator assignment (-=) & Unary operator '--' used 에러 메시지 Assignment (=) can be replaced with operator assignment (-=). Unary operator '--' used 코드 간단한 숫자 카운터 만드는 중 증감식에서 발생 const handleAdd = () => { count = count + 1; }; const handleMinus = () => { count--; }; 해결 const handleAdd = () => { count += 1; }; const handleMinus = () => { count -= 1; }; 2023. 2. 27. eslint Error: A form label must be associated with a control. 에러 메시지 A form label must be associated with a control. eslint (jsx-a11y/label-has-associated-control) -> label은 input과 연관되어야 한다 에러 코드 이메일 에러 원인 htmlFor과 id로 연결해도 에러 발생 -> React에서는 컴포넌트 재상요으로 인해 id의 유일성 보장하기 못하기 때문 (map()으로 리스트를 만들 때 key값에 index를 넣었을 때도 비슷한 문제가 발생했었다) 해결 방법 2가지 [1] .eslint.json에 아래 내용 추가 { "rules": { "jsx-a11y/label-has-associated-control": [ 2, { "labelAttributes": ["htmlFor"] }.. 2023. 2. 16. 이전 1 다음 728x90 반응형