A very simple light weight react-component that animates your number updates.
yarn add number-scroller
https://number-scroller.netlify.app/
Simply supply a 'to' prop and it will scroll to that number (By default, it takes 1 second to reach the new value)
import React, { useState } from 'react';
import NumberScroller from 'number-scroller';
const MyNumber = () => {
const [number, setNumber] = useState(100);
return (
<p>
<NumberScroller to={number} timeout={1000} />
</p>
);
};
import Reactfrom "react";
import NumberScroller from "number-scroller";
const MyNumber = () => {
return (
<p>
<NumberScroller to={100} renderFrequency={25} />
</p>
);
};
import React from 'react';
import NumberScroller from 'number-scroller';
const MyNumber = () => {
return (
<p>
<NumberScroller from={100} to={20} />
</p>
);
};
import React from 'react';
import NumberScroller from 'number-scroller';
const MyNumber = () => {
return (
<p>
<NumberScroller to={100} decimalPlaces={2} />
</p>
);
};
import React from 'react';
import NumberScroller from 'number-scroller';
const MyCurrencyComponent = () => {
return (
<p>
<NumberScroller
to={100}
localeStringProps={[
'en-US',
{
style: 'currency',
currency: 'USD'
}
]}
/>
</p>
);
};