I am very new to react and I am trying to bring in data from a food2fork api but I am getting the error
TypeError: Cannot read property 'map' of undefined
if i undo this code, the error was none. this code is main place to occur error
{recipes.map (recipe => {
return <Recipe key={recipe.recipe_id} recipe={recipe}
/>;
})}
Full Page of RecipeList.js
import React, { Component } from 'react';
import Recipe from './Recipe';
import RecipeSearch from './RecipeSearch';
export default class RecipeList extends Component {
render() {
const { recipes } = this.props;
return (
<React.Fragment>
<RecipeSearch />
<h1>Recipe List</h1>
<div className="container my-5">
{/* title */}
<div className="row">
<div className="col-10 mx-auto col-md-6 text-center text-uppercase mb-3">
<h1 className="text-slanted">Recipe List</h1>
</div>
</div>
{/* end title */}
<div className="row">
{recipes.map (recipe => {
return <Recipe key={recipe.recipe_id} recipe={recipe}
/>;
})}
</div>
</div>
<Recipe />
</React.Fragment>
);
}
}
In App.js:
render(){
console.log(this.state.recipes);
return (
<React.Fragment>
<RecipeList />
<RecipeDetails />
</React.Fragment>
);
}
this.props.recipesis undefined. Please add the script where you're importing RecipeList component.this.propsTothis.props.recipes, but it is still showing error<RecipeList .../>App.jsor other js files in component folder it is need to be add