1.0.1 • Published 3 years ago

react-use-circuit-breaker v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-use-circuit-breaker

React hook that works like circuit breaker.

NPM JavaScript Style Guide Node.js CI semantic-release

Install

npm install --save react-use-circuit-breaker

Usage

import { useCircuitBreaker } from 'react-use-circuit-breaker'

/**
 * Execute callback function that passed by third argument
 * when send function called 2 times in 5 seconds.
 */
const [send] = useCircuitBreaker(2, 5000, () => {
  throw new Error("The breaker trips!");
});

send();
send();
send(); // => Uncaught Error: The breaker trips!

License

MIT © h-tachikawa


This hook is created using create-react-hook.