@shopify/polaris
Version:
Shopify’s product component library
17 lines (16 loc) • 655 B
JavaScript
import { useRef } from 'react';
import { useIsAfterInitialMount } from './use-is-after-initial-mount';
/**
* Similarly to the lifecycle hook componentDidMount, useComponentDidMount
* will be invoked after the component has mounted, and only the initial mount.
* @param callback Defines a callback to invoke once the component has
* initially mounted.
*/
export function useComponentDidMount(callback) {
const isAfterInitialMount = useIsAfterInitialMount();
const hasInvokedLifeCycle = useRef(false);
if (isAfterInitialMount && !hasInvokedLifeCycle.current) {
hasInvokedLifeCycle.current = true;
return callback();
}
}