cdvntr / react-native-confetti

Raining confetti made with react native animations
MIT License
221 stars 55 forks source link

Move initialisation to constructor in Confetti.js #18

Closed joshjhargreaves closed 6 years ago

joshjhargreaves commented 6 years ago

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 in componentWillMount to state initialisation in the constructor or a property initialiser: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state

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.