Skip to content

useOnDraw

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

Accepts a function without arguments.

Calls it when the component was drawn.

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

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

function Component(props) {
  useOnDraw(() => {
    document.addEventListener(/*...*/)
  })

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

export default afc(Component)
Clone this wiki locally