question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] motion component should be a constructor

See original GitHub issue

Problem

When using libraries that have components, I want to make that component inherit the motion.element props.

When it’s my own component, the motion.element isn’t a problem because I can add any classes but how can I make a component called <Dropdown /> Inherit motion props? I can’t simply wrap it around a motion component because it can throw the styling off.

Solution

If we make the motion export also be a constructor that can allow me to create a new component that can be animated like so:

const MotionDropdown = motion(Dropdown);

Other libraries

Currently react-spring has this functionality with their animated component. https://www.react-spring.io/docs/hooks/basics

const AnimatedDonut = animated(donut);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

2reactions
mattgperrycommented, May 22, 2020

Yeah but this is a method on motion, not a prop.

const Component = React.forwardRef((props, ref) => {
  return <div ref={ref} />
})

const MotionComponent = motion.custom(Component)

export default App() {
  return <MotionComponent animate={} />
}
1reaction
focuxcommented, Sep 14, 2020

Yes, it’s not on the docs, I searched it for a while with no luck but glad I could find this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass component constructor in React props?
you can pass component functions as props. You almost got the answer. const Lunch = (props) => { return ( // React.createElement(props.
Read more >
Render Props - React
A component with a render prop takes a function that returns a React element and calls it instead of implementing its own render...
Read more >
Component Replication | Unreal Engine Documentation
To make a component replicate, simply call AActorComponent::SetIsReplicated(true) . If your component is a default subobject, this should be done in the class ......
Read more >
Custom View Components | Android Developers
You can supply a constructor which can take attributes and parameters from the XML, and you can also consume your own such attributes...
Read more >
Stateful vs. Stateless Functional Components in React - Code
Its scope is limited to the current component. A component can initialize its state and update it whenever necessary. The state of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found