ReactJS map function cannot find property of undefined

后端 未结 3 444
情书的邮戳
情书的邮戳 2021-01-16 07:10

I\'m still learning ReactJS. I\'m challenging myself to write a very basic todo app (as one does) and I\'m having an issue calling an onClick function.

var L         


        
3条回答
  •  梦谈多话
    2021-01-16 07:47

    You should bind this explicitly to the handleClick function to be referring to the React component not the map function, so you can refactor your code as follow:

    var items = list.map(renderListItem.bind(this));
    

    And add renderListItem method in your React class as follow:

    renderListItem(item) {
      return (
        
  • ); }

提交回复
热议问题