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

109
Visualizações
How to change styled-component styles by clicking on component with help of useState hook?

I want to change width of the StyledDivGrid component by clicking on it, but using this code, when I click on this div nothing happens. I can't realize what the problem is. Help, pls

const StyledDivGrid = styled.div`
  display:flex;
  flex-wrap: wrap;
  width: ${props=>props.width};
  height: 120px;
  position: relative;
  background-color: lightcoral;
`
function App() {
  let [state, setState] = useState(
    <StyledDivGrid width = {'120px'}></StyledDivGrid>
  )
  setState = () => {
      <StyledDivGrid width = {'240px'}></StyledDivGrid>;
  }
  
  return (
  
      <StyledDivGrid onClick = {() => setState()}>
        
      </StyledDivGrid>  
    
  );
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const StyledDivGrid = styled.div`
   display:flex;
   flex-wrap: wrap;
   width: ${props=>props.width};
   height: 120px;
   position: relative;
   background-color: lightcoral;
`
function App() {
  const [width, setWidth] = useState("120px")
   
  return (

  <StyledDivGrid onClick={ () => setWidth("240px")} width={width}>
    
  </StyledDivGrid>  

  );
}

Didn't check the code and I guess you are using styled-components , i hope this is useful

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