Uncaught TypeError: Cannot read property 'Checked' of undefined - ReactJS

前端 未结 3 838
醉话见心
醉话见心 2020-12-21 16:45

I am trying to create a simple a TODO list app in ReactJS. My basics of React are not very clear so I am stuck here.

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 17:05

    You need set this for .map (you can do that through second argument in .map)

    return 
      {this.props.items.map(createItem, this)}
    ;

    Example

    because now in createItem this refers to global (in browsers it will be window) score (or if you use strict mode this will be undefined)

    as you use babel you also can use arrow functions

    var createItem = (item) => {
      return 
  • {item.text}
  • ; }; return
      {this.props.items.map(createItem)}
    ;

    Example

提交回复
热议问题