Bug: incorrect `interpolatingStyle` value for `Motion` after `onRest`
See original GitHub issueExample: http://www.webpackbin.com/N16jKp-cz
import React, {PureComponent } from 'react';
import {render} from 'react-dom';
import {Motion, spring} from 'react-motion';
class App extends PureComponent {
constructor(...args) {
super(...args);
this.state = {
x: spring(10)
}
this.onRest = this.onRest.bind(this);
}
onRest() {
// changing to a number value
this.setState({
x: 100
});
}
render() {
return (
<Motion defaultStyle={{x: 0}} style={this.state} onRest={this.onRest}>
{interpolatingStyle => {
return (
<div>
{/* on final render this should be '100' but it is the last spring value: '10' */}
interpolated x: {interpolatingStyle.x} <br/>
{/* on final render this renders '100' as expected */}
current x: {JSON.stringify(this.state.x)}
</div>
)
}}
</Motion>
)
}
}
render(<App />, document.getElementById('app'));
Workaround: put update on the end of the stack
onRest() {
setTimeout(() => {
this.setState({
x: 100
});
});
};
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
onRest seems to cause React-Motion to ignore rerenders #322
But to make it work I have to wrap setState in onRest callback with setTimeout , otherwise new step value is ignored in...
Read more >How to fix "that" problem in After Effects - YouTube
I know I know. You've probably figured this out by now, but it took me a few months to know why After Effects...
Read more >react-motion | Yarn - Package Manager
Specifies both the rounding of the interpolated value and the speed (internal). It's normal not to feel how stiffness and damping affect your...
Read more >Robotic Motion Planning: Bug Algorithms
A boundary following behavior invoked when heuristic distance increases. • A value d min which is the shortest distance observed thus far between...
Read more >Stopping false positive motion triggered by bugs attracted to ...
I set up four G3 Pro and one G4 cameras for outdoor monitoring and I'm finding the Unifi Protect software not as great...
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 Free
Top 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
Yeah setTimeout is necessary to use with onRest. I reckon this has something to do with async nature/batching of setState in React.
We can probably switch to setState(pureCallback) notation as now recommended. Hopefully it would eliminate the problem.
You may check https://github.com/nkbt/react-motion-loop with my workaround, which is the same…
if you check source of react-collapse@3 you will find fairly ugly but working solution with instance vars. I had to figure out when animation ends properly and comparing with end values is not the right one, since spring can go into negative values in many cases.