3.0.1 • Published 2 years ago

@webscopeio/react-health-check v3.0.1

Weekly downloads
23
License
MIT
Repository
github
Last release
2 years ago

React Health Check 🏥

Lightweight React hook for checking health of API services.

stable tslib checks license


Installation 🧑‍🔧

npm i @webscopeio/react-health-check

or

yarn add @webscopeio/react-health-check

Examples 😲

Usage ❓

const { available, refresh } = useHealthCheck({
  service: {
    name: 'auth',
    url: 'https://example.com/auth/health',
  },
  onSuccess: ({ service, timestamp }) => {
    console.log(`Service "${service.name}" is available since "${timestamp}" 🎉`);
  },
  onError: ({ service, timestamp }) => {
    console.log(`Service "${service.name}" is not available since "${timestamp}" 😔`);
  },
});

You can also create a global configuration so you don't have to define services and callbacks every time:

// App wrapper
<HealthCheckConfig
  value={{
    services: [
      {
        name: 'auth',
        url: 'https://example.com/auth/health',
      },
      {
        name: 'payment',
        url: 'https://example.com/payment/health',
      },
    ],
    onSuccess: ({ service, timestamp }) => {
      console.log(`Service "${service.name}" is available since "${timestamp}" 🎉`);
    },
    onError: ({ service, timestamp }) => {
      console.log(`Service "${service.name}" is not available since "${timestamp}" 😔`);
    },
  }}
>
  <App />
</HealthCheckConfig>;

// Later in some child component
const { available } = useHealthCheck('auth');

Configuration 🛠

useHealthCheck() hook accepts a configuration object with keys:

KeyTypeDescription
serviceService<S = string>Object defining an API service to be checked.
onSuccess(state: ServiceState<S>) => void;Callback which should be called when API service becomes available again.
onError(state: ServiceState<S>) => void;Callback which should be called when API service becomes unavailable.
refreshIntervalnumberPolling interval for health checks in milliseconds. Default value: 5000
refreshWhileHiddenbooleanDetermines whether polling should be paused while browser window isn't visible. Default value: false

Global configuration accepts the same keys as useHealthCheck() hook with the exception of "service". You need to specify array of "services" when using global configuration.

License 💼

MIT | Developed by Webscope.io

3.0.1

2 years ago

3.0.0-next.4

3 years ago

3.0.0-next.5

3 years ago

3.0.0

3 years ago

3.0.0-next.3

3 years ago

3.0.0-next.2

3 years ago

3.0.0-next.1

3 years ago

3.0.0-next.0

3 years ago

2.2.0-next.2

4 years ago

2.2.0-next.1

4 years ago

2.2.0

4 years ago

2.2.0-next.0

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0-rc.6

4 years ago

2.0.0-rc.5

4 years ago

2.0.0-rc.4

4 years ago

2.0.0-rc.3

4 years ago

2.0.0-rc.2

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago