Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Framer Motion in React class components (non-functional)

I have a simple animation with Framer Motion that works perfectly on functional component but doesn’t work on class component
I am new to Framer Motion and That is my react code =>

import {motion} from 'framer-motion'

class Sidebar extends React.Component {
  constructor (props) {
    super(props)
  }

  render (){
    return (
      <>
        <motion.section
          inital={{ width: 0, height: 0, opacity: 0 }}
          animate={{ width: "100%", height: "100%", opacity: 1 }}>
       
        </motion.section>
      </>
    )
  }
}

export default Sidebar

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have a typo in your code, inital should be initial (missing i after t). Besides that your code is fully functional and framer motion works same with class components as it does with functional (but of course you can’t use hooks from framer motion in class components)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading