A
A
asqwerty2022-01-06 17:13:18
React
asqwerty, 2022-01-06 17:13:18

How to understand which element we are on?

I have 2 arrays.
1 array is an array of objects. Each object is a product card
2 array is an array of objects. Each object is detailed information about this product.
In both arrays, objects have IDs that are the same for objects in the first and second arrays. That is, for example, the object of the first array with field ID = 5 corresponds to the object of the second array with field ID = 5.
Using the map function, I draw react components (cards) based on the first array. Each card has a "details" button, which, when clicked, should open a modal with detailed information about the product. Accordingly, the modal will be drawn based on the object from the second array.
But I don’t understand how to understand on which card we clicked the “more details” button in order to find the desired object in the second array by ID and pass it to the modal.
That is, when I click on the "more" button on the card, I need to understand what ID this card has and by this ID find the object in the second array in order to pass it to the modal. And I don't understand how to do it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2022-01-06
@rPman

when you form the card code, pass this id to your method call
how do you write the reaction code? generating an attribute with a function call? or you register on javascript by an anonymous method? in both cases feel free to pass id

V
Vladimir, 2022-01-06
@Casufi

https://reactjs.org/docs/thinking-in-react.html
product card is a separate component,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question