I'm getting an error when I'm rendering my react components and I think it has to with how my table are nested from component to component.
I'm getting this error Text nodes cannot appear as a child of <tbody>
I'm looking at answers here and here but I cannot see what I'm doing wrong with my nesting of the tables, to get this error.
My nesting for my tables is:
<table>
<thead>
<tr></tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
Here is my code:
import React, {Component} from 'react';
import './App.css';
class DataTable extends Component {
constructor(props) {
super(props);
this.state = {
dataBaseJSON: {},
dataBaseItems: []
};
}
componentDidMount() {
fetch('https://ghibliapi.herokuapp.com/films').then(results => {
return results.json();
}).then(jsonResults => {
this.setState({
dataBaseJSON: jsonResults
});
return jsonResults
}).then(jsonResults => {
Object.keys(jsonResults).forEach(movieObject => {
this.setState({
dataBaseItems: this.state.dataBaseItems.push(<DataRow key={this.state.dataBaseJSON[movieObject].id}
item={this.state.dataBaseJSON[movieObject]}/>)
})
});
})
}
render() {
return (
<table>
<thead>
<tr>
<th>Title</th>
<th>Director</th>
<th>Producer</th>
<th>Release Date</th>
<th>Rotten Tomato Score</th>
</tr>
</thead>
<tbody>
{this.state.dataBaseItems}
</tbody>
</table>
)
}
}
class DataRow extends Component {
render() {
return (
<tr>
<td>{this.props.item.title}</td>
<td>{this.props.item.director}</td>
<td>{this.props.item.producer}</td>
<td>{this.props.item.release_date}</td>
<td>{this.props.item.rt_score}</td>
</tr>
)
}
}
class App extends Component {
render() {
return (
<div>
<h1 className="App-title">Welcome to React</h1>
<div>
<DataTable/>
</div>
</div>
);
}
}
export default App;