use-animated-number
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Vite Plugin - React.js Animated Number

A custom React hook for animating numbers in React.js applications.

version

Installation

You can install this plugin through npm:

npm i use-animated-number

Usage


Example

import { useState } from "react";
import useAnimatedNumber from "use-animated-number";

export default function Header() {
    const duration: number = 300;
    const [ balance, setBalance ] = useState<number>(0);
    const animatedBalance: string = useAnimatedNumber(balance, duration);

    const increase = () => {
        const randomIncrement: number = Math.floor(Math.random() * 100) + 1;
        setBalance(prevState => prevState + randomIncrement);
    }

    return (
        <section>
            <span> {animatedBalance} </span>
            <button onClick={increase}>Increase balance</button>
        </section>
    )
}

License

License

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i use-animated-number

    Weekly Downloads

    6

    Version

    0.0.5

    License

    GPL-3.0

    Unpacked Size

    37.3 kB

    Total Files

    3

    Last publish

    Collaborators

    • mustafadalga