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

前端 未结 5 1435
暗喜
暗喜 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条回答
  •  -上瘾入骨i
    2020-12-11 10:36

    if you are already using ES6

    I would change the code a bit, so it will easier to understand and work with no special glitches with events target and attributes

    lists.map(list => {
        return (
           

    Hello World

    Foo Bar
    ) }) handleClick = (listId) => { console.log(listId) // other stuff }

    as you can see here, I just call the method with the list id and I'm done

提交回复
热议问题