setState use call inside of <Animated.Code> memory leak
See original GitHub issuei try to update my state from animated value, and i subscribe to the animated value and update my state, but it causes memory leak, it updates every 10ms even if the animated value is not changed, i only want the state to be updated when there is a change in the animated value, where i can call from a shouldcomponentUpdate(prevState), but it seems like it can’t retrive the animated value outside of the render. i wonder what is the best way to do this. here is my code:
console.log
const {call} = Animated
class SomeComponent extends Component {
constructor(props) {
super(props);
this._transY = new Value(0);
this.state = { height: "", };
}
updateHeight = value => {
requestAnimationFrame(() => {
this.setState({ newHeight: value });
});
};
render(){
return (
<Animated.View>
<Animated.Code>{() => call([this._transY], this.updateHeight)}</Animated.Code>
</Animated.View>
)
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
setState use call inside of <Animated.Code> memory leak #332
i try to update my state from animated value, and i subscribe to the animated value and update my state, but it causes...
Read more >Memory leak when using setState to overwrite value flutter
This error can occur when code calls setState() from a timer or an animation callback. E/flutter ( 6791): The preferred solution is to ......
Read more >Solving Memory Leaks with React Native - Enquero
In essence, memory leaks can be defined as memory that is not required by an application anymore that for some reason is not...
Read more >Avoid Memory Leak With React SetState On An Unmounted ...
Specifically, calling setState() in an unmounted component means that your app is still holding a reference to the component after the component ......
Read more >Understanding React's useEffect cleanup function
React's useEffect cleanup function saves applications from unwanted behaviors like memory leaks by cleaning up effects.
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
@osdnk would it make sense to rewrite
Animated.Code
as a functional component withuseCode
in order to ensure that the behavior is consistent between the two? If yes, I’d be happy to make a PR.Implemented @wcandillon suggestion in #952.