Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 테코테코
- 항해플러스
- redux-toolkit
- react
- 매일메일
- Python
- 자바
- redux
- react-redux
- redux-saga
- programmers
- 알고리즘
- createSlice
- 리액트
- JavaScript
- react-router
- 항해99
- 이코테
- SW
- sw expert academy
- C++
- java
- useDispatch
- Algorithm
- json-server
- Get
- 코딩테스트합격자되기
- maeil-mail
- 프로그래머스
- axios
Archives
- Today
- Total
Binary Journey
[React][CRUD] 리액트로 간단한 게시판 페이지 만들어보기 - [Issue] React 는 Date() 를 rendering 하지 못한다. (Objects are not valid as a React child) 본문
React/게시판만들기 v1.
[React][CRUD] 리액트로 간단한 게시판 페이지 만들어보기 - [Issue] React 는 Date() 를 rendering 하지 못한다. (Objects are not valid as a React child)
binaryJournalist 2020. 11. 3. 14:14반응형
목차 돌아가기: binaryjourney.tistory.com/pages/ReactCRUD-create-board-tutorial
date를 화면에 나타내 보려다 계속해서 만난 오류
Objects are not valid as a React child
찾아보니 new Date 이거나 Date의 값인 경우 Object라서 리액트에서 렌더링을 못한다는 것이다.
그래서 toString()을 해줘야 한다고 한다.
참고한 사이트:
stackoverflow.com/questions/41604539/objects-are-not-valid-as-a-react-child
현재 서버에는 날자가 이런형식으로 들어가 있고
이를 ArticleDetail 에서 props로 받아 이렇게 toString 해줘야 한다.
// ArticleDetail
<tr>
<th>날짜</th>
<td>{new Date(props.date).toString()}</td>
</tr>
화면에서 날짜를 드디어 볼 수 있다.
format를 바꾸고 싶다면 toString() 말고 다른 걸 써도 된다.
예를 들어 toLocaleString() 을 쓰면
<tr>
<th>날짜</th>
<td>{new Date(props.date).toLocaleString()}</td>
</tr>
이렇게 나타난다.
(화면에 나타난 Comment 는 무시하길 바란다)
목차 돌아가기: binaryjourney.tistory.com/pages/ReactCRUD-create-board-tutorial
반응형