Reputation: 55
hi guys i try to make onclick inside map looping , so the onclick inside the div , but i got error , infinite looping
here the code
{arrayqueue.map((item, index) => {
return (
<div className="row-queue" key={index} onClick={setMyvideo(item.videoname)}>
<div className="column1-queue">{index + 1}</div>
<div className="column2-queue">{item.title}</div>
<div className="column3-queue">{item.singer}</div>
</div>
);
})}
can someone help me why this is error ?
Upvotes: 0
Views: 51
Reputation: 8751
https://reactjs.org/docs/hooks-state.html
const [myvideo, setMyvideo] = useState(...)
...
{arrayqueue.map((item, index) => {
return (
<div className="row-queue" key={index} onClick={() => setMyvideo(item.videoname)}>
<div className="column1-queue">{index + 1}</div>
<div className="column2-queue">{item.title}</div>
<div className="column3-queue">{item.singer}</div>
</div>
);
})}
Upvotes: 1