componentWillMount has always fired before the first render in React, and this case we would get a red screen if this._rotateAnimation and this._xAnimation were not initialised before the first render.
As with moving the setState call to a simple initialisation in the constructor, it is also safe for us to move the initialisation of the rotateAnimation and xAnimation Animated values to the constructor from componentWillMount.
In React 16.4
componentWillMount
is one of the 3 deprecated methods as per: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html. I propose removing its use in favour of using the constructor.The blogpost gives an example where they recommend refactoring a
setState
call incomponentWillMount
to state initialisation in the constructor or a property initialiser: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-statecomponentWillMount
has always fired before the first render in React, and this case we would get a red screen ifthis._rotateAnimation
andthis._xAnimation
were not initialised before the first render.As with moving the
setState
call to a simple initialisation in the constructor, it is also safe for us to move the initialisation of therotateAnimation
andxAnimation
Animated values to the constructor fromcomponentWillMount
.