Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
click button to toggle show one component and hide another component in reactjs

I have two separate button like grid and list button:

<button 
     onClick={() => setClassName('jsGridView')}
     title="Grid View"
 >
     <IoGrid className="active" size="25"/>
</button>  

<button 
     onClick={() => setClassName('jsListView')}
     title="List View"
   >
    <BiAlignLeft size="25"/>
</button>

const [cName, setClassName] = useState('jsGridView');  

So when i click Grid view button it will show this component:

<GridCard className={cName}/>

and when i click list view button it will show

<ListCard className={cName}/>

with this mentioned className..

class is changed button but show hide component is not working.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can display different components depending on the value of cName.

<div className="row mt-4 book-div">
   <div className={cName}>   
   { cName === 'jsGridView' ? <BooksGridCard/> : <BooksListCard/> } 
   </div>
</div>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda