I have 3 containers (div) I want that when clicking on one of these the one I am selecting is highlighted. I don't know what kind of css can help me or if in its effect I would have to use a function.
This is my code:
import '../assets/styles/OptionContainer.css';
const OptionContainer = (props) => {
return (
<section className='itemsSelected'>
<div className='rows'>
Filas
<br />
<button className='btnSelect'></button>
</div>
<article className='container_col_val'>
<div className='columns'>
Columnas
<br />
<button className='btnSelect'></button>
</div>
<div className='values'>
Valores
<br />
<button className='btnSelect'></button>
</div>
</article>
</section>
)
}
export default OptionContainer;
This is how the containers look, I need that when you select one, for example rows, it is highlighted and remains active, but if I click on another then the other is the one that is activated and so on
Use a hook like
React.useState
to define a state that lets you know which element is active at all times. The state you define can be oneindex
or any kind of identifier that allows you to differentiate one element from another, that way you will know when to apply the active state or not.You can use the following example as a reference (press run and you will see how it works):