UNPKG

@anton.bobrov/react-vevet-hooks

Version:

A collection of custom React hooks designed to seamlessly integrate with the `Vevet` library

31 lines 912 B
import { useEffect } from 'react'; import { vevet } from 'vevet'; /** * Custom React hook that triggers an effect once the page has fully loaded. * * @example * const MyComponent = () => { * useOnPageLoad(() => { * console.log('Page has loaded!'); * }, []); * * return <div>Welcome to my website!</div>; * }; */ export function useOnPageLoad(effect, deps) { useEffect(function () { var unsubscribe; var promise = vevet.onPageLoad(); promise .then(function () { unsubscribe = effect(); }) .catch(function () { }); return function () { promise.cancel(); unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe(); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, deps); } //# sourceMappingURL=useOnPageLoad.js.map