use-progress-bar
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

use-progress-bar

Hook to use progress bar in React

Demo

Open in CodeSandbox

demo

Installation

$ yarn add use-progress-bar

Usage

import React from 'react'
import { useProgressBar } from 'use-progress-bar'

const ProgressBar = ({ isLoading }) => {
  const { status, progress } = useProgressBar(isLoading)

  const style = {
    opacity: status !== 'progress' ? 0 : 1,
    top: 0,
    position: 'absolute',
    left: 0,
    display: 'block',
    background: '#29d',
    width: `${progress}%`,
    height: '4px',
    transition: `width 200ms ease-in, opacity 200ms ease-in 200ms`,
    zIndex: 10,
  }

  return <div style={style} />
}

useProgressBar()

useProgressBar(isLoading: boolean, options?: Options): ProgressBar

ProgressBar

  • status: 'idle' | 'progress' | 'completed'
  • progress: number

Options

  • duration?: number
    • Default: 11000 ms
    • Progress time to the max
  • frequency?: number
    • Default: 200 ms
    • Frequency of progress updates
  • max?: number
    • Default: 80
    • Maximum progress until completion

Package Sidebar

Install

npm i use-progress-bar

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

20.2 kB

Total Files

18

Last publish

Collaborators

  • trzmaxim