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

158
Views
component re-render always while hover on sidebar how can i optimize

I have a sidebar in the web app and when the cursor hovers it sidebar expands and when the cursor leaves it collapses. I attach my console screenshot in 15sec re-render trigger a lot. But while hovering all parts of the sidebar state continue to change. how can I stop continuing re-rendering of components? Here is the code and you can see it in the console also. CodeSandbox link

  const [state, setState] = useState({
    sidebarClass: ''
  });

  const onHandleMouseOver = () => {
    setState(pre => ({
      ...pre,
      sidebarClass: 'expend'
    }))
  }
  const onHandleMouseLeave = () => {
    setState(pre => ({
      ...pre,
      sidebarClass: 'collapse'
    }))
  }

  console.log('component re-render')

  return (
    <div 
    onMouseOver={onHandleMouseOver}
    onMouseLeave={onHandleMouseLeave}

    className={`App ${state.sidebarClass}`}
    >
      
    </div>
  );

error

about 4 years ago · Juan Pablo Isaza
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!