Props 读取未定义的问题

Issues with Props reading undefined

我正在处理我的项目(repo 如果您想查看完整代码)。该应用程序使用 Spotify API 进行搜索,并允许您将它们存储在播放列表中,然后将其保存到您的帐户中。我可以搜索数据库并调出曲目,但是当我尝试将它们添加到播放列表时,我会抛出一个错误 TypeError: Cannot read property 'props' of undefined In my Track component on the "This.props.isRemoval" statement in renderAction().问题是一切都很好,包括所有 this.props 值。因此,我为整个列表记录了 this.props.isRemoval,它应该将它们全部记录为 false。有任何想法吗?跟踪组件:

import React from 'react';
import './Track.css';


export class Track extends React.Component {
 constructor(props) {
  super(props);
  this.addTrack = this.addTrack.bind(this);
  this.removeTrack = this.removeTrack.bind(this);
 }

 addTrack() {
  this.props.onAdd(this.props.track);
 }

 removeTrack() {
  this.props.onRemove(this.props.track);
 }

 renderAction() {
  if(this.props.isRemoval) {
   this.removeTrack();
  } else {
   this.addTrack();
  }
 }

 render() {
  return(
   <div className="Track">
      <div className="Track-information">
      {console.log(this.props.isRemoval)}
        <h3>{this.props.name}</h3>
        <p>{this.props.artist} | {this.props.album}</p>
      </div>
      <a className="Track-action" onClick={this.renderAction}>+</a>
   </div>
  );
 }
}

export default Track;

此外,如果你想看看我的回购协议来帮助我,我没有深入研究这个问题,但它只让我搜索可能存储的术语 "Hello"出于某种原因,因为这是我使用的第一个术语,但即使停止节点服务器并重新启动它,它也将我锁定到相同的关键字

像您所做的那样在构造函数中绑定您的 renderAction 函数:

this.addTrack = this.addTrack.bind(this);
this.removeTrack = this.removeTrack.bind(this)
this.renderAction  = this.renderAction.bind(this);