Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda