0

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 ?

4
  • 1
    can you share you setMyvideo function and also the error msg Commented Nov 6, 2020 at 4:27
  • 2
    You need to pass a function which calls setMyVideo, not a function call directly. So it should be onClick={() => setMyvideo(item.videoname)} Commented Nov 6, 2020 at 4:28
  • 1
    @Jayce444 its fine if setMyvideo is a HOF which returns a function Commented Nov 6, 2020 at 4:29
  • 1
    @Jerryc yes that's true, I just assumed it wasn't since this seemed like a beginner asking, and they tend not to use HOFs very much. But yes Riky, you can add your setMyVideo definition if this doesn't fix it to help clarify things. And include the specifics of your error message, it's exact text, where in the code it's happening, etc. Commented Nov 6, 2020 at 4:31

1 Answer 1

1

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>
  );
})}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.