All Projects → glennreyes → React Countup

glennreyes / React Countup

Licence: mit
💫 A configurable React component wrapper around CountUp.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Countup

Laravel Visits
📊 Laravel Visits is a counter that can be attached to any model to track its visits using Redis or Eloquent. (with tags, IP protection and caching)
Stars: ✭ 582 (-45.25%)
Mutual labels:  counter
Pytest Patterns
A couple of examples showing how pytest and its plugins can be combined to solve real-world needs.
Stars: ✭ 24 (-97.74%)
Mutual labels:  incremental
Omg Counters
😍 Increment decrement counters using various frontend frameworks.
Stars: ✭ 44 (-95.86%)
Mutual labels:  counter
Differential Datalog
An incremental programming language
Stars: ✭ 488 (-54.09%)
Mutual labels:  incremental
Camels
camels game
Stars: ✭ 17 (-98.4%)
Mutual labels:  incremental
Madoka Python
Memory-efficient Count-Min Sketch Counter (based on Madoka C++ library)
Stars: ✭ 24 (-97.74%)
Mutual labels:  counter
Node Measured
A Node metrics library for measuring and reporting application-level metrics, inspired by Coda Hale, Yammer Inc's Dropwizard Metrics Libraries
Stars: ✭ 500 (-52.96%)
Mutual labels:  counter
Spincounterview
🎡 一个类似于码表变化的旋转计数器动画控件
Stars: ✭ 47 (-95.58%)
Mutual labels:  counter
Syscrack
Virtual Online Crime Simulator (VOCS) written in PHP 7.0
Stars: ✭ 17 (-98.4%)
Mutual labels:  incremental
Ingraph
Incremental view maintenance for openCypher graph queries.
Stars: ✭ 40 (-96.24%)
Mutual labels:  incremental
Counterfab
A FloatingActionButton subclass that shows a counter badge on right top corner
Stars: ✭ 725 (-31.8%)
Mutual labels:  counter
Github Profile Views Counter
It counts how many times your GitHub profile has been viewed. Free cloud micro-service.
Stars: ✭ 781 (-26.53%)
Mutual labels:  counter
Vue Twitter Counter
Counter component inspired in Twitter with Vue
Stars: ✭ 29 (-97.27%)
Mutual labels:  counter
Moxie
lightweight platform-agnostic tools for declarative UI
Stars: ✭ 691 (-35%)
Mutual labels:  incremental
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (-95.77%)
Mutual labels:  counter
Tree Sitter
An incremental parsing system for programming tools
Stars: ✭ 7,083 (+566.32%)
Mutual labels:  incremental
Multipletimers
Stars: ✭ 24 (-97.74%)
Mutual labels:  counter
Backintime
Back In Time - A simple backup tool for Linux
Stars: ✭ 1,066 (+0.28%)
Mutual labels:  incremental
Bartycrouch
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.
Stars: ✭ 1,032 (-2.92%)
Mutual labels:  incremental
App
Just a little analytics insight for your personal or indie project
Stars: ✭ 40 (-96.24%)
Mutual labels:  counter

React CountUp

GitHub license Build Status Coverage Status Version Downloads Gzip size

A configurable React component wrapper around CountUp.js.

Click here to view on CodeSandbox.

Looking for v3.x docs?

Click here to get to the previous docs.

react-countup

Table of Contents

Installation

yarn add react-countup

Usage

import CountUp from 'react-countup';

Simple example

<CountUp end={100} />

This will start a count up transition from 0 to 100 on render.

Render prop example

<CountUp
  start={-875.039}
  end={160527.012}
  duration={2.75}
  separator=" "
  decimals={4}
  decimal=","
  prefix="EUR "
  suffix=" left"
  onEnd={() => console.log('Ended! 👏')}
  onStart={() => console.log('Started! 💨')}
>
  {({ countUpRef, start }) => (
    <div>
      <span ref={countUpRef} />
      <button onClick={start}>Start</button>
    </div>
  )}
</CountUp>

The transition won't start on initial render as it needs to be triggered manually here.

Tip: If you need to start the render prop component immediately, you can set delay={0}.

More examples

Manually start with render prop

<CountUp start={0} end={100}>
  {({ countUpRef, start }) => (
    <div>
      <span ref={countUpRef} />
      <button onClick={start}>Start</button>
    </div>
  )}
</CountUp>

Autostart with render prop

Render start value but start transition on first render:

<CountUp start={0} end={100} delay={0}>
  {({ countUpRef }) => (
    <div>
      <span ref={countUpRef} />
    </div>
  )}
</CountUp>

Note that delay={0} will automatically start the count up.

Delay start

<CountUp delay={2} end={100} />

Hook

Simple example

import { useCountUp } from 'react-countup';

const SimpleHook = () => {
  const { countUp } = useCountUp({ end: 1234567 });
  return <div>{countUp}</div>;
};

Complete example

import { useCountUp } from 'react-countup';

const CompleteHook = () => {
  const { countUp, start, pauseResume, reset, update } = useCountUp({
    start: 0,
    end: 1234567,
    delay: 1000,
    duration: 5,
    onReset: () => console.log('Resetted!'),
    onUpdate: () => console.log('Updated!'),
    onPauseResume: () => console.log('Paused or resumed!'),
    onStart: ({ pauseResume }) => console.log(pauseResume),
    onEnd: ({ pauseResume }) => console.log(pauseResume),
  });
  return (
    <div>
      <div>{countUp}</div>
      <button onClick={start}>Start</button>
      <button onClick={reset}>Reset</button>
      <button onClick={pauseResume}>Pause/Resume</button>
      <button onClick={() => update(2000)}>Update to 2000</button>
    </div>
  );
};

API

Props

className: string

CSS class name of the span element.

Note: This won't be applied when using CountUp with render props.

decimal: string

Specifies decimal character.

Default: .

decimals: number

Amount of decimals to display.

Default: 0

delay: ?number

Delay in seconds before starting the transition.

Default: null

Note: delay={0} will automatically start the count up.

duration: number

Duration in seconds.

Default: 2

end: number

Target value.

prefix: string

Static text before the transitioning value.

redraw: boolean

Forces count up transition on every component update.

Default: false

preserveValue: boolean

Save previously ended number to start every new animation from it.

Default: false

separator: string

Specifies character of thousands separator.

start: number

Initial value.

Default: 0

startOnMount: boolean

Use for start counter on mount for hook usage.

Default: true

suffix: string

Static text after the transitioning value.

useEasing: boolean

Enables easing. Set to false for a linear transition.

Default: true

easingFn: (t: number, b: number, c: number, d: number) => number

Easing function. Click here for more details.

Default: easeInExpo

formattingFn: (value: number) => string

Function to customize the formatting of the number

onEnd: ({ pauseResume, reset, start, update }) => void

Callback function on transition end.

onStart: ({ pauseResume, reset, update }) => void

Callback function on transition start.

onPauseResume: ({ reset, start, update }) => void

Callback function on pause or resume.

onReset: ({ pauseResume, start, update }) => void

Callback function on reset.

onUpdate: ({ pauseResume, reset, start }) => void

Callback function on update.

Render props

countUpRef: () => void

Ref to hook the countUp instance to

pauseResume: () => void

Pauses or resumes the transition

reset: () => void

Resets to initial value

start: () => void

Starts or restarts the transition

update: (newEnd: number?) => void

Updates transition to the new end value (if given)

Protips

By default, the animation is triggered if any of the following props has changed:

  • duration
  • end
  • start

If redraw is set to true your component will start the transition on every component update.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].