Socket
Socket
Sign inDemoInstall

react-multi-busy

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-multi-busy

React Context library for controlling multiple busy indicators in an application


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-multi-busy

React Context library for controlling multiple busy states (spinners, progress bars, etc.) in an application

NPM JavaScript Style Guide

Examples

Install

npm install --save react-multi-busy

Usage

Wrap your component tree w/ the MultiBusyProvider:

import ReactDOM from 'react-dom'
import { MultiBusyProvider } from 'react-multi-busy'
ReactDOM.render(
  <CssBaseline>
    <MultiBusyProvider>
      <App />
    </MultiBusyProvider>
  </CssBaseline>,
  document.getElementById('root')
)

Implement the useMultiBusy custom hook in any component that you want to control the busy state for:

import { useMultiBusy } from 'react-multi-busy'

export const SomeComponent = () => {
  const {isBusy, startBusy, endBusy} = useMultiBusy()
  const busy = isBusy()
  return <Button {...{
    color: 'primary',
    variant: 'contained',
    onClick: goFetchSomething(startBusy, endBusy)
  }} >
    <span>{
      `${ busy ? 'I\'m busy' : 'Click Me' }`
    }</span>
    { busy && <CircularProgress {...{
      size: '1em',
    }} /> }
  </Button>
}

Finally, make startBusy() and endBusy() methods available to whatever it is that you want to use to control the state of:

// This could easily be a redux-thunk
const goFetchSomething = (startBusy, endBusy) => async () => {
  startBusy()
  const result = await someService()
  endBusy()
  return result
}

License

MIT © RavenHursT

FAQs

Package last updated on 15 Jun 2021

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc