Skip to content

useOnDestroy

Александр edited this page Jan 17, 2023 · 1 revision
export function useOnDestroy(callback: () => void): void

Accepts a function without arguments.

Calls it when the component was unmounted.

The same as React.useEffect(() => callback, [])

import { afc, useOnDestroy } from 'react-afc'

function Component(props) {
  useOnDestroy(() => {
    document.removeEventListener(/*...*/)
  })

  return () => {/*...*/}
}

export default afc(Component)
Clone this wiki locally