Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply motion to react component Framer-Motion

I know that I can apply motion directly to element/HTMLtag like this:

<motion.div>some content</div>

But how can I apply it to this?

<Comp />

Without wrapping it inside another HTML element, like in React-Transition-Group library.

Framer API provides Frame component, but it acts like permanent additional HTML element with own styling, and it is messing my layout.

like image 492
Andrew Avatar asked Jun 25 '20 11:06

Andrew


People also ask

Can you use framer Motion without React?

Framer Motion improves upon and simplifies the API in a way that couldn't have been done without breaking changes and rewriting. One difference is that whereas Framer Motion only has support for React, Pose has support for React-Native and Vue.

Which is better framer Motion or React spring?

Framer Motion uses the more traditional duration-and-location approach. Most developers likely have experience with this animation strategy and it will feel familiar. React-Spring approaches animations using spring-physics. This is a well-executed attempt to make animations feel and behave like real-life movement.

Can I use material UI with framer Motion?

Material-UI has component prop option for this kind of requirement and should do better and more elegant approach than the wrapping-approach. Then, you can pass any props provided by framer-motion package to your Material-UI component as long as they're not conflicted (i'm not sure if any). Show activity on this post.


1 Answers

If anyone comes to this page seeking for the solution of how to apply motion from Framer-Motion library to your React Component and not the direct DOM element like "div" or "span", here it is:

motion.custom()

Example of use:

import { Link } from "react-router-dom"

const MotionLink = motion.custom(Link)

return <MotionLink />

As for today it is not mentioned in the official documentation, or it is in someplace deep and hard to find.

I had found it in BUG reports here, there is a Codesanbox that illustrates my example, created by the person who reported a bug.

like image 70
Andrew Avatar answered Oct 04 '22 06:10

Andrew