Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!