1.0.0 • Published 6 months ago

@paroi/use-async-effect v1.0.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 months ago

@paroi/use-async-effect

The React hook 'useEffect', but asynchroneous.

Usage

useAsyncEffect(async () => {
  await somethingAsync();

  return async () => {
    // the cleanup code can be async too
  }
}, [dep1, dep2])

It's optional but a logger can be configured:

<AsyncEffectLoggerProvider value={console}>
  {/* your application here */}
</AsyncEffectLoggerProvider>

When a logger is configured, then useAsyncEffect catches all the errors and calls logger.error.

1.0.0

6 months ago