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

133
Views
Changing classes in React component successfully, but does not animate appropriately

I have a component that is changing classes every render in order to animate that component depending on its state with Tailwind:

import { useState, useEffect, useRef } from 'react'

export default function LeftToolbox() {
    const [isOut, setIsOut] = useState(true)
    const [classNames, setClassNames] = useState('hover:animate-slideIn h-full w-14 position absolute bg-red-800' +
        ' left-0 z-40')

    useEffect( () => {
        isOut && setClassNames('hover:animate-slideIn h-full w-14 position absolute bg-red-800 left-0 z-40')

        !isOut && setClassNames('hover:animate-slideOut h-full w-14 position absolute bg-red-800 left-0 z-40')
    },  [isOut])
    return (
        <div
             onMouseEnter={() => setIsOut(false)}
             onMouseLeave={() => setIsOut(true)}
             className={classNames}></div>
    )
}

The component's classes change appropriately, according to onMouseEnter and onMouseLeave, but the actual animation it self does not work

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!