I'm trying to render an object inside an element (Panel element in react-bootstrap).
import React, { PropTypes } from 'react';
import { Panel } from 'react-bootstrap';
const NetworkDetail = React.createClass({
render () {
return (
<Panel header="Network Details" bsStyle="info">
{this.props.dataDetail && Object.keys(this.props.dataDetail).map(function(detail, id) {
return <span key={id}>{this.props.dataDetail[detail]}</span>;
}.bind(this))}
</Panel>
)
}
})
export default NetworkDetail
But that doesn't work. The error thrown is
Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {self}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of 'NetworkDetail'.
What I don't understand is that if I use
return <span key={id}>{this.props.dataDetail.myProperty}</span>;
it works.
How can I render all the properties and values of my object ?
props.dataDetailsmight resolve an object inthis.props.dataDetail[detail]?dataDetailobject has actually a property named_linkswhich is an object... (the app consumes a REST HATEOAS backend). If this_linksobject is the cause, how should I get rid of ? Maybe with underscore.js (I actually already use underscore.js to reformat my data) ?omitfunction to filter_links. A better option might be to create a list of the keys you want to render and use Underscore'spickfunction instead. See: underscorejs.org/#omit