簡體   English   中英

未捕獲的TypeError:無法讀取react-redux中未定義的屬性'props'

[英]Uncaught TypeError: Cannot read property 'props' of undefined in react-redux

我收到錯誤Uncaught TypeError: Cannot read property 'props' of undefined當我嘗試更改react-redux中的狀態道具時, Uncaught TypeError: Cannot read property 'props' of undefined ,這是我要更改的代碼:

class Home extends Component {
  componentWillMount(){
    this.props.fetchMatches();
  }

  handleChange(newDateRange){
    this.props.fetchMatches({
      ...this.props,
      startDate: newDateRange[0],
      endDate: newDateRange[1]
    })
  }

請執行下列操作:

handleChange = (newDateRange) => {
    this.props.fetchMatches({
      ...this.props,
      startDate: newDateRange[0],
      endDate: newDateRange[1]
    })
  }

或在構造函數中

constructor(){
    super(props);
    this.handleChange = this.handleChange.bind(this);
}

handleChange ,它是不是能夠找到context ,由於它this是不確定的。 您將必須明確綁定this或使用箭頭功能

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM