Answer the question
In order to leave comments, you need to log in
How to find out the element that was clicked?
I am creating a dropdown list. The problem I encountered is that when you click on one list, all lists open at once. For lists I used useState. I understand that I need to add e.target, but I don’t understand how exactly to connect it with useState. Tell me please.
const [show, setShow] = useState(false);
<div
className="class"
onClick={(e) => setShow(!show)}
>
</div>
Answer the question
In order to leave comments, you need to log in
Output an array of lists through map, and hang on click the id of the element that was clicked, as an option.
onClick={() => handleClick(id)}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question