Mongo Objects are not valid as a React child


#1

I am pulling data from a mongo db into a container with withtracker

export default AppContainer =  withTracker (() => {
  return {
    records: Records.find({}).fetch(),
  }
}) (App);

but when I try and access the date as below from the App component it gives me the above error.

{this.props.records.map((record) => {
   return (
      <div>{record.createddate}</div> 
    )
    })}

I have tried all kinds of conversions for the mongo db date field but to no avail.

I think I am now on React 16

What newbie nonsense am I missing?

Many thanks


#2

I managed to get this working with moment…

{moment.utc(record.createddate).format('DD/MM/YYYY')}


#3

Yes and meteor or mongo are both completely irrelevant here. This is a react thing. It does not know how to render an object. Since createddate is probably a plain javascrip date object, you cannot directly use it and must convert it to a string. You don’t have to use moment either, you can use any of the built in date output/formatting functions to resolve the issue.