@app-elements/use-mount

A (P)React hook that calls a function after the component is mounted, and possibly when unmounted.

Usage no npm install needed!

<script type="module">
  import appElementsUseMount from 'https://cdn.skypack.dev/@app-elements/use-mount';
</script>

README

useDocumentClick

A (P)React hook that calls a function after the component is mounted, and possibly when unmounted.

Installation

npm install --save @app-elements/use-mount

Usage

import { useMount } from '@app-elements/use-mount'

const MyComponent = () => {
  useMount(() => alert('MOUNTED'), /* () => alert('UNMOUNTED') */)
  return null
}

Props

Prop Type Default Description
onMount Function None Function to invoke on component mount
onUnmount Function None Function to invoke on component unmount