piral-hooks-utils
Version:
Hooks and HOC for pilets and Piral instances.
58 lines (31 loc) • 1.96 kB
Markdown
[](https://piral.io)
[Piral Hooks Utils](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-hooks-utils) [](https://jestjs.io) [](https://discord.gg/kKJ2FZmK8t)
A set of hooks and HOCs for pilets and Piral instances.
# Installation
This should only be installed as a dependency (`dependencies`) as it is only designed mostly for runtime/consumption by Piral or pilets. You could also share it explicitly or implicitly from your Piral instance if you'd like to optimize usage in your pilets. It's not required though as the code provided by it is minimal and tree-shakable.
If you'd love to use yarn:
```sh
yarn add piral-hooks-utils
```
Alternatively, npm works reliably, too:
```sh
npm i --save piral-hooks-utils
```
# Included Hooks
The following hooks are included.
## `useAfterVisible`
A hook to indicate something was suddenly visible.
## `useAsyncReplace`
Gives a full async lifecycle in a hook.
## `useLockBodyScroll`
Hook that locks scrolling on the main document.
## `useOnClickOutside`
Hook that detects if a click outside the given reference has been performed.
## `useOnScreenVisible`
Hook that detects if a reference element within the main document is visible.
## `usePiletApi`
Retrieves the Pilet API stored in the provider.
## `usePrompt`
Hook to notify the user in case of potential data loss when performing a page transition (internal or external).
# License
Piral is released using the MIT license. For more information see the [license file](./LICENSE).