I have set up a sandbox to illustrate my problem: Link to codesandbox
When you click ‘All’ and then a year, it doesnt animate the boxes. It also skips animating the other way around on the elements from a specific year. If you click a year and then ‘All’. Only new elements are animated.
How could I solve this with framer-motion?
I have tried using the key propery on the <motion.div> element but without any success.
2
Answers
I figured it out. What I needed was to put layout prop on the <motion.div. You can read more about it here: layout animations
I updated my codesandbox with that prop. You can view the working codesandbox here: Working sandbox
You should try adding
<AnimatePresence>
with some additional props. Here is an example link to codeSandboxAnimation Properties for
<motion.div>
Your Each Array item div should look like