728x90
반응형

 

📖 에러 경위

Date 날짜를 화면에 나타내보려다가 이런 에러 메세지를 만났다.

Objects are not valid as a React child (found: [object Date]).

 

📌 에러 원인

찾아보니 new Date 이거나 Date의 값인 경우 Object라서 리액트에서 렌더링을 못한다는 것이다.

 

 

 

 

💡 결론

toString()을 해줘야 한다고 한다.

 

그런데!!!

toLocaleString('ko-KR') 

이런식으로 하면 굳이 따로 설정하지 않아도 내가 원하는 방식대로 나오네?!

 

 

 

[참고사이트]

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

 

Date.prototype.toLocaleString() - JavaScript | MDN

The toLocaleString() method returns a string with a language-sensitive representation of this date. In implementations with Intl.DateTimeFormat API support, this method simply calls Intl.DateTimeFormat.

developer.mozilla.org

https://stackoverflow.com/questions/41604539/objects-are-not-valid-as-a-react-child

 

Objects are not valid as a React child

I am getting an below error. I can see that I have to return array instead of object. But I am really not sure how to fix it. Thanks in advance Objects are not valid as a React child. If you mea...

stackoverflow.com

 

728x90
반응형