How To Access The key attribute?
Unanswered
Raymond posted this in #help-forum
RaymondOP
I have the following element from which I want to print the key (randomly generated)
How can I access the key value?
<li key={Math.floor(Math.random() * 1000000)} draggable={true} onClick={(event) => {
console.log(event.currentTarget.key); // this doesn't work
}}>{item.name}</li>How can I access the key value?
3 Replies
you don't access the key...
you generate the id of your
item and then use the item.id as the keyyou also pass the
item to the prop so that you can also access the .id inside the component