Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objects are not valid as a React child getting error when adding div?

I am just rendering the data and display in between divs but I am getting error this

Objects are not valid as a React child (found: Wed Dec 09 1998 00:00:00 GMT+0530 (India Standard Time)). If you meant to render a collection of children, use an array instead.

<Fragment key={String(index) + String(i)}>
                    <div>{displaytext}</div>
                    <div>{value}</div>
                  </Fragment>

Only issue is on this line <div>{value}</div> if I remove this line everything works fine.If I add this line I am getting above error why ? here is my code https://codesandbox.io/s/ooj2wowy9q

like image 312
user944513 Avatar asked Dec 10 '18 22:12

user944513


3 Answers

React doesn't allow objects like Dates or Arrays as children, you need to convert value to string, like this:

<div>{new Date(value).toString()}</div>

Hope this helps you!

like image 61
Miguel Angel Avatar answered Oct 11 '22 20:10

Miguel Angel


value is a date object. Try this:

<div>{moment(value).format('DD-MM-YYYY')}</div>
like image 25
wdm Avatar answered Oct 11 '22 20:10

wdm


I think you might be using a date wrongly

<div>{value.toDateString()}</div>

might solve the problem

like image 40
Rithik Sunny Avatar answered Oct 11 '22 19:10

Rithik Sunny