Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question