CODE:
var React = require('react');
var Ingredient = require('./Ingredient.jsx')
var Recipe = React.createClass({
getInitialState: function() {
return {
showIngredients: false
};
},
handleClick: function() {
this.setState({
showIngredients: !this.state.showIngredients
});
},
render: function() {
var i = 0;
var ingredientsList = this.props.ingredients.map(function(item) {
i++;
return <Ingredient key={i} name={item}/>;
});
return (
<table>
<tbody>
<tr className="recipeName" onClick={this.handleClick}>
<td>{this.props.name}</td>
</tr>
{this.state.showIngredients ? {ingredientsList} : null }
</tbody>
</table>
);
}
});
module.exports = Recipe;
This generates the following error:
main.js:18463 Uncaught Error: Invariant Violation: Objects are not valid as a React child (found: object with keys {ingredientsList}). 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
Recipe.