Socket
Socket
Sign inDemoInstall

react-number-scroller

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-number-scroller

A lightweight react-component that animates your numbers.


Version published
Maintainers
1
Install size
42.8 kB
Created

Readme

Source

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>
  );
};

Keywords

FAQs

Last updated on 02 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc