UNPKG

@livelybone/use-mounted

Version:

React hook for mounted and unmount, return an object: MutableRefObject<{ mounted: boolean, unmounted: boolean }>

10 lines (8 loc) 633 B
/** * Bundle of @livelybone/use-mounted * Generated: 2020-07-15 * Version: 1.0.5 * License: MIT * Author: 2631541504@qq.com */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("react")):"function"==typeof define&&define.amd?define(["react"],n):(e=e||self).useMounted=n(e.React)}(this,function(u){"use strict";return function(e){var n=u.useRef(e);n.current=e;var t=u.useRef({mounted:!1,unmounted:!1});return u.useEffect(function(){t.current.mounted=!0,t.current.unmounted=!1;var e=n.current&&n.current();return function(){"function"==typeof e&&e(),t.current.unmounted=!0}},[]),t}});