I
I
IIITRIX2020-01-19 13:40:31
React
IIITRIX, 2020-01-19 13:40:31

How to change class on click React?

Help please
There are 3
divs By default, 1 div is always visible, if I click on the second one, the first one is hidden, the second one is shown, and so on.
If you click in any other place, div 1 will be visible

<div className='global'>
  <div style={{ display: 'block' }}></div>
  <div style={{ display: 'none' }}></div>
  <div style={{ display: 'none' }}></div>
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abberati, 2020-01-19
@abberati

https://www.google.ru/search?q=how+to+toggle+class...

S
seropaski, 2020-01-21
@seropaski

As an option to store the active element in the state. That is, by clicking on the element, we write its any identifier to the state, in the div we check what the variable from the state is equal to and decide whether to show the div or not.
And by clicking in any other place - you can use a custom hook, as an option. For example, such

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question