본문 바로가기

JavaScript3

Web - N년 전, N개월 전, N일 전, N시간 전, N분 전, 방금 전 코드 구현하기 Date관련된 기능들은 만들기 겁나 귀찮다.그래서 그냥 ChatGPT에게 만들어 달라고 했다. 그랬더나 GPT가 함수 하나를 만들어 줬다.원래 Date의 prototype에 해당 기능을 장착하려 했으나 prototype 사용을 권장하지 않고 상속으로 해결하라는 스택오버플로우의 답변을 듣고 Date를 상속받는 CustomDate클래스를 만들었다.코드는 아래와 같다.class CustomDate extends Date { getTimeAgo = (): string => { const now = new Date(); const years = now.getFullYear() - this.getFullYear(); const months = (now.getFullYear.. 2024. 7. 4.
Web - "React does not recognize the customStyle prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase customstyle instead."에러 해결하는 법 크롬 개발자 도구에서 Console창을 보니까 이런 이상한 에러가 콘솔창을 도배하고 있었다.React does not recognize the customStyle prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase customstyle instead.customStyle을 React가 못 알아먹고 있으니까 customstyle로 이름을 바꾸라는 소리다. 하지만 소문자로 바꿔도 계속 경고 메세지가 출력된다.이때는 변수 앞에다가 '$'를 붙이면 문제가 해결된다.export const Container = styled.div` ${props =>.. 2024. 7. 2.
Web - "Assign object to a variable before exporting as module default import/no-anonymous-default-export"에러 해결하는 법 이번 포스팅에서는 "Assign object to a variable before exporting as module default import/no-anonymous-default-export"에러를 해결하는 방법을 알려드리겠습니다.아래와 같이 AuthAPI클래스를 생성해서 export해주고 있는데export default new AuthAPI(); 아래와 같이 const변수에 저장한 뒤 export하면 해결됩니다.Object타입일 경우도 마찬가지 입니다.const authApi = new AuthAPI();export default authApi; 2024. 7. 2.