0
I have the following components:
Obj
import React from 'react';
export default class Obj extends React.Component {
constructor(props) {
super(props);
console.log(props);
}
render() {
let objs = Object.entries(this.props.data)
.map((keyValue, index) => (
<p key={index}><b>{keyValue[0]}</b> - {keyValue[1]}</p>
));
console.log(objs);
return <div>{objs}</div>
}
}
and Modal:
import React from 'react';
export default class Modal extends React.Component {
constructor(props) {
super(props);
}
close(e) {
e.preventDefault();
e.stopPropagation();
this.props.onCloseModal();
}
render() {
if (!this.props.isModalOpen) {
return <div></div>;
}
return (
<div class="modal" style={{ display: "block" }}>
<div class="modal-content">
<div class="modal-header">
<span class="close" onClick={e => this.close(e)}>×</span>
<h2>Details</h2>
</div>
<div class="modal-body">
{this.props.children}
</div>
</div>
</div>
);
}
}
In the parent component they are like this:
render() {
return (
<div>
<Modal
isModalOpen={this.state.isModalOpen}
onCloseModal={this.onCloseModal.bind(this)}
>
<Obj data={this.state.data} />
</Modal>
</div>
);
}
When the call is made {this.props.children}
the Act claims.
Objects are not Valid as a React Child (found: Object with Keys...
Could someone explain what I’m doing wrong?
Thank you.
@Edit Sub objects are not understood by React they need to be treated for Nodes.
Daniel I’m trying to pass an object to the Obj Component that renders all the Keys and values of the past object, and I’m trying to throw that into the modal.
– Lucas Bertollo
So if I pass an object {key:'value', key1:'value1'} to obj it would open a modal with <div><p>key - value</p><p>key1 - value1</p></div>
– Lucas Bertollo
I understood Deniel, the returned object had other objects inside and the Act did not understand these sub objects
– Lucas Bertollo