Created
April 13, 2021 18:50
-
-
Save madcoda/85fb1bc416fb289efa22e932626abad7 to your computer and use it in GitHub Desktop.
React Animated Number component using react-countup update when end changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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