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

how to stop framer motion animation run on every re rendering

I am using framer motion for animation and my problem is the animation triggers with every re rendering on my page. the behavior that I want is to animation only once on page entering or reloading not by re rendering. here is my component:

const WrapperLoginFlow = () => {

     const MotionCard = motion(Card);


     return (

        <MotionCard
           initial={{ scale: 0, opacity: 0 }}
           animate={{ scale: 1, opacity: 1 }}
           transition={{ duration: 0.5 }}
        >
           <div>
             something
           </div>

        </MotionCard>
 )};

I have some state in this component that might cause re rendering the page and it cause the animation starts when ever my page re renders. how can I stop this?

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

>Solution :

You can move const MotionCard = motion(Card); out of your component.

If it is in your component, at every render, it will create again the motion component and trigger the animation.

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