react-number-scroller
TypeScript icon, indicating that this package has built-in type declarations

3.4.0 • Public • Published

react-number-scroller

A very simple light weight react-component that animates your number updates.

Scrolling Number

Installation

yarn add react-number-scroller

See Prop Table and Storybook Examples Here!

https://react-number-scroller.netlify.app/

Examples

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 'react-number-scroller';

const MyNumber = () => {
  const [number, setNumber] = useState(100);
  return (
    <p>
      <NumberScroller to={number} timeout={1000} />
    </p>
  );
};

Optionally, you can set the render interval manually (milliseconds between each render)

import Reactfrom "react";
import NumberScroller from "react-number-scroller";

const MyNumber = () => {
  return (
    <p>
      <NumberScroller to={100} renderFrequency={25} />
    </p>
  );
};

Optionally, Customize the starting value with the 'from' prop (defaults from 0)

import React from 'react';
import NumberScroller from 'react-number-scroller';

const MyNumber = () => {
  return (
    <p>
      <NumberScroller from={100} to={20} />
    </p>
  );
};

Format the number with set number of decimals

import React from 'react';
import NumberScroller from 'react-number-scroller';

const MyNumber = () => {
  return (
    <p>
      <NumberScroller to={100} decimalPlaces={2} />
    </p>
  );
};

Format the number to a locale string such as currency

import React from 'react';
import NumberScroller from 'react-number-scroller';

const MyCurrencyComponent = () => {
  return (
    <p>
      <NumberScroller
        to={100}
        localeStringProps={[
          'en-US',
          {
            style: 'currency',
            currency: 'USD'
          }
        ]}
      />
    </p>
  );
};

Package Sidebar

Install

npm i react-number-scroller

Weekly Downloads

136

Version

3.4.0

License

MIT

Unpacked Size

43.8 kB

Total Files

17

Last publish

Collaborators

  • kevinvandy