useMount

A React Hook that runs a function only once when the component mounts.

Demo

Source

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

useMount(callback, strictOnce)

Callback

A function that will be called when the component mounts, can be async.

StrictOnce

Warning

strictOnce option is NOT recommended as it damages the original intention of the Strict Mode of React 18.

A boolean that indicates whether the handler should be called only once in Strict Mode of React 18. Default is false.