Not working with AnimatePresence in 2.0
See original GitHub issueBased on the example from the release notes:
function New() {
const [ isOpen, setOpen ] = React.useState( false )
const { layerProps, triggerProps, renderLayer } = useLayer({ isOpen })
return (
<AnimatePresence>
<button onClick={() => setOpen( !isOpen )} {...triggerProps}>Trigger</button>
{isOpen && renderLayer( <motion.div {...layerProps}>Layer</motion.div> )}
</AnimatePresence>
)
}
This triggers the following error:
Uncaught Error: react-laag: Could not find a valid reference for the layer element. There might be 2 causes:
- Make sure that the 'ref' is set correctly on the layer element when isOpen: true. Also make sure your component forwards the ref with "forwardRef()".
- Make sure that you are actually rendering the layer when the isOpen prop is set to true
It does work when I replace the <AnimatePresence>
with a Fragment (<>
).
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 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 >framer-motion animate presence unmount - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >Chakra UI + Framer Motion
Chakra UI + Framer Motion. This example shows how to add some interesting motion interaction or animation to your Chakra UI websites or...
Read more >Page Transitions with Gatsby + Framer Motion - Janessa Garrow
Some knowledge of Framer Motion is also helpful, but not necessary. ... Using AnimatePresence allows us to give a motion component an exit ......
Read more >framer-motion | Yarn - Package Manager
Fixing AnimatePresence children not re-rendering when their exiting siblings ... Fixed unit type conversion not working with previously-undefined values.
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
Ok, so my bad, I changed the implementation and it’s working fine. Thanks!
That is a valid concern, but I think this will not be so bad. v2 has a lazy strategy regarding monitoring positioning, meaning that only layers that are open are affected. Also I did some perf-measuring in a production setting (node.env === ‘production’ / without animations though). On a macbook pro (2017) calculating a single position for 1 layer takes ~ less than 0.1ms. In other words, it can take quite a lot. Haven’t tested it with lots of animations though. Will put this on my todo-list to pick up somewhere this week 😃