Riky
Riky

Reputation: 55

make onclick inside map reactjs

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

Answers (1)

wangdev87
wangdev87

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

Related Questions