I am a little confused with the map function when using it in a React Component. I have a Recipes Component that gets passed the recipes data from the App Component.
APP COMPONENT
<Recipes recipes={recipes} />
RECIPES COMPONENT
export default class Recipes extends Component {
// THIS FUNCTION IS RETURNING NOTHING
renderRecipes() {
return this.props.recipes.map((recipe) => {
<h1>{recipe.name}</h1>
});
}
render() {
let recipe = this.props.recipes.map((recipe) => {
return (
<h1>{recipe.name}</h1>
);
});
return(
<div>
// CALLING THE FUNCTION HERE DOES NOT WORK
{ this.renderRecipes() }
// HOWEVER CALLING THE VARIABLE DOES WORK
{ recipe }
</div>
);
}
}
Here is where I am confused. Creating a function which does the map function returns nothing, however moving the map function and assigning the output to the recipe variable inside render() works fine. Why does the map function in renderRecipes return nothing?
renderRecipes