div's id attribute is undefined/not getting captured onClick in a react app

前端 未结 5 1440
暗喜
暗喜 2020-12-11 10:05

I\'m mapping data from the api response and rendering multiple divs out of it. Along with that I\'m assigning a unique id from the response to the id attribute of each div l

5条回答
  •  春和景丽
    2020-12-11 10:33

    In the constructor, just put this line:

    constructor() {
         this.handleClick = this.handleClick.bind(this);
    }
    

    After this, you will be able to access the ref to the element,

    For more detail please go through this link : https://reactjs.org/docs/handling-events.html

提交回复
热议问题