Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding framer-motion initial animations on mount

Please see this codesandbox.

I have a basic framer-motion animation where the height of a box is animated when toggled. However, I want the box to be shown by default, but when the page loads the initial animation is presented.

My question is, how do I avoid having an initial animation for a component if it should be shown on mount, but still maintain future enter and exit animations? Thanks!

like image 679
Jimmy Avatar asked Apr 18 '26 16:04

Jimmy


1 Answers

Bit old of a question, but just in case some people stumble upon this. if you are using an AnimatePresence you can use initial={false} on the AnimatePresence component. Like so,

<AnimatePresence initial={false}>
  {someCondition ? (
    <motion.h1 {...yourProps}>
      yooo
    </motion.h1>
  ) : null}
</AnimatePresence>

More info here: https://www.framer.com/motion/animate-presence/##suppressing-initial-animations

edit: doc link update (oct 20th 2024)

like image 196
cody Avatar answered Apr 20 '26 06:04

cody