2017-10-09 1 views
0

私はエラーを受け取りますCannot read property 'handleDeleteAll' of undefined。 これは私のコードです:子どもの要素へのアクセス行動

const RecipeList = (props) => { 

const Items = props.recipes.map((recipe) => { 
    return <RecipeListItem key={recipe.id} recipe={recipe} /> 
}); 
     console.log(props); 
     return (
     <div> 
      <button onClick={this.props.handleDeleteAll}>Remove All</button> 
      <div> 
      {Items} 
      </div> 
     </div> 
    ) 
} 
export default RecipeList; 

そして、これはレポです:https://github.com/kstulgys/fcc-recipe-box/blob/master/src/components/RecipeList.js

答えて

1

RecipeListは機能しませクラスです。ハンドラはprops.handleDeleteAllで、this.props.handleDeleteAllではなくアクセスできます。

+0

あまりにも簡単にするために、このライン

<button onClick={this.props.handleDeleteAll}>Remove All</button> 

。どうもありがとう! – karolis2017

1

RecipeListはステートレス機能コンポーネントなので、this.propsは未定義です。

変更このライン

<button onClick={props.handleDeleteAll}>Remove All</button> 
関連する問題