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

106
Vistas
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 Respuestas
Responde la pregunta

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 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