Skip to content

useLayoutEffectOnce ​

Hook to executes effect and clean up after component mount only once. It prevents React 18 StrictMode behavior if present, otherwise it works like a normal useLayoutEffect with empty dependencies array.

N.B. Not use in a component with normal useLayoutEffect, if it executes a React.DispatchAction, because this action is executes twice if there is React.StrictMode.

Demo ​

INFO

The implementation is like that useEffectOnce.

Please visit useEffectOnce example to see how it works.

Released under the MIT License.