AnimatePresence exit not working for me...
See original GitHub issueDunno if this is a bug or if i’m doing something wrong, but the exit prop does not seem to be working for me. Here is my code:
<AnimatePresence exitBeforeEnter>
<Container
{...props}
initial={{
opacity: 0
}}
animate={{
opacity: 1,
transition: {
delay: 3,
duration: 5
}
}}
exit={{
opacity: 0,
transition: {
delay: 3,
duration: 5
}
}}
>
{props.children}
</Container>
</AnimatePresence>
…based on the code above, i am expecting the component to wait 3 seconds, then fade out over 5 seconds, then wait 3 seconds, then fade in over five seconds.
what actually happens is that the component fades out instantly, then about six seconds pass, then it fades in over 5 seconds…so, the piece that does not seem to be working is the fade out over 5 seconds as the component exits…
do you think this might be a bug or m i doing something incorrect here?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Animate Presence exit not working framer motion
The reason that this is not working is that you have to explicitly specify the key of the child that you are conditionally...
Read more >Exit animation with `framer-motion` demystified
Re-render when all exit animation are done The final step is to re-render the AnimatePresence component when all the exit animation are ...
Read more >Framer Motion exit animation is not working : r/reactjs - Reddit
Hello, I am trying to use framer-motion and want to animate an exit, this is how I am defining the motion div: {isOpen(point)...
Read more >Page Transitions In React
Thankfully, Framer Motion solves this problem with Animate Presence. Coupled with exitBeforeEnter , it allows developers to create amazing page transitions. It ...
Read more >framer motion | enter and exit animations - YouTube
I was really surprised by this video, it was a bit hard to find (videos on the first few pages not having what...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@amcc The direct child(ren) of
AnimatePresence
need to be either changingkey
or mounting/unmounting to fire exit animations. Here, the direct child isContainer
, which never does either. So this isn’t going to work.Additionally,
AnimatePresence
needs to be rendered consistently to track changes to its children. This is an unavoidable constraint of React. AlthoughTransition
here is being rendered byLayout
in a consistent way,Layout
itself is being mounted/unmounted every render. You can see this by adding auseEffect
:This will fire every time a page changes. This means that each
AnimatePresence
component is an entirely new instance of the component, so it has no connection to any otherAnimatePresence
components that may have been rendered in the past.Your usage in the example above is correct - as long as
Transition
itself isn’t remounting. Which it seems to be here. I don’t know enough about the Gatsby template system to know if there’s a way around this.you are doing something wrong. AnimatePresence will detect which children has been mounted or unmounted. You have Container that is ALWAYS rendered as a children. It will never animate because Container is always mounted; it never unmounts, so you wont get any animation
On top of that, you also have to give “key” prop to each children, so that AnimatePresence can detect them.