React, get index of component

Does anyone know how to get the index position of this button (it is multiplied several times)?

Are you saying that inside the <ApplicationsTable> component, it makes multiple buttons via some sort of loop? Wouldn’t the index be available in that loop?

1 Like

Look at row.slice() in the beggining and extraRow at the end. I just dont get it

1 Like

From the render code, where you call extraRow(), you’ll need to pass in the index coming from the map. Then adjust your normalBtn function to accept an index parameter. I guess…

Something like this?
But i can’t finde the way to show/call that index.

Pass the index to your showSomething call in the click handler.

Undefined :frowning:

It would be much easier if you posted (a link) to all of your code.

onClick={(event, index) => showSomething(event, index)}

You overwrote the index in the upper scope by defining it as another parameter here. Don’t do that.

onClick={(event) => showSomething(event, index)}

Still undefined. Sorry[index] what’s this? Just log index. If that’s undefined, then go to the next call in the stack, and log it there, if it’s still undefined then go up to the next call in the stack and log it there to try and debug it.

You’ve got like three or four levels of function calls that the index needs to get passed through.

You totally right, thanks, it works perfectly. Great technical and practical way to explain a solution. Thanks a tons.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.