ameyms / react-animated-number

React component for animating numbers
MIT License
168 stars 28 forks source link

Change initialValue if new initialValue is provided #22

Open samrith-s opened 6 years ago

samrith-s commented 6 years ago

I have a case where my numbers keep changing between any of the 5 items from an array of [200, 300, 500, 128, 11]. As soon as the page loads, I do NOT want the counter to animate. So I pass initialValue and value as the same variable.

{
  initialValue: 200,
  value: 200,
  animated: false //expected
},
{
  initialValue: 200,
  value: 300,
  animated: true //expected
},
{
  initialValue: 300,
  value: 200
  animated: false // this is happening because initialValue is set in the state of the component and doesn't update, so it only counts up, but doesn't count down to the initialValue.

I think this is should be fixed as for a finite number of units that need animating, this might become a recurring issue.

samrith-s commented 6 years ago

I can take this up and make a PR for it.