Skip to content

Instantly share code, notes, and snippets.

@madcoda
Created April 13, 2021 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madcoda/85fb1bc416fb289efa22e932626abad7 to your computer and use it in GitHub Desktop.
Save madcoda/85fb1bc416fb289efa22e932626abad7 to your computer and use it in GitHub Desktop.
React Animated Number component using react-countup update when end changed
import React, {useEffect} from 'react';
import { useCountUp } from 'react-countup';
export default function AnimatedNumber({ value, decimals }){
const { countUp, update } = useCountUp({ start:0, end: value, decimals, duration:1.5 });
useEffect(() => {
update(value);
}, [value])
return countUp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment