M
M
MRcracker2021-11-03 20:29:29
React
MRcracker, 2021-11-03 20:29:29

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

1 answer(s)
D
Denis Masson, 2021-11-03
@pumbasl

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 question

Ask a Question

731 491 924 answers to any question