Basic TransitionMotion
See original GitHub issueI’m trying to animate in/out a single component when mounted, however am struggling to find a basic example that doesn’t animate a list/internal state/etc.
I might be misunderstanding how react-motion works, is this possible in a simple way?
// Transition container
class Transition extends React.Component {
willLeave() {
return {opacity: spring(0)}
}
willEnter() {
return {opacity: spring(1)}
}
getStyles() {
return [{key: 'one', style: {opacity: spring(1)} }]
}
render() {
return (
<div>
<TransitionMotion styles={this.getStyles()} willLeave={this.willLeave} willEnter={this.willEnter}>
{int => <div style={{opacity: int.opacity}}> hello there </div>}
</TransitionMotion>
</div>
)
}
}
// Main container
export default class Container extends React.Component {
constructor(){
super()
this.state = {
openCard: false,
}
}
openCard(props) {
this.setState({ openCard: !this.state.openCard })
}
render() {
return <div> {this.state.openCard ? <Transition/> : null } </div>
)
}
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:9
Top Results From Across the Web
Simple Transition with React Motion | by Zak Risha - Medium
We are going to make a new component, I'm going to call mine Transition . We will also need to import two items...
Read more >Introduction to React Motion - LogRocket Blog
In this guide, we'll demonstrate how to install the library and share some basic tips to help you build natural-looking, physics-based ...
Read more >react - <TransitionMotion> - Web Coding Center
<TransitionMotion> helps you to do mounting and unmounting animation. 'Square c' shrinks till disappearance.RESETRUNFULL import React from 'react ...
Read more >React Motion · GitBook - Tidepool
Tools for even simple CSS3-based animations on mounting and unmounting ... Because its TransitionMotion API suits most of our use cases and because...
Read more >Doodle Lines Transition Motion Array 2022 || Simple. Easy. And ...
Hey guys in this video we will learn Doodle Lines Transition Motion Array that you can apply in your videos. There are 24...
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
I am using it for Route transitions, which is essentially the same thing (swapping out a single component). Here is my full RouteTransition component:
It is used like this:
@boyswan My component is guaranteed to have a child, but yours isn’t.
You would have to do something like:
It’s easier if you’re already dealing with an array. In that case you just use
.map
:Unfortunately in React,
this.props.children
can be either an array or a single element.