@nextui-org/use-is-mounted
Advanced tools
Comparing version 0.0.0-dev-v2-20230328184744 to 0.0.0-dev-v2-20230329200753
type UseIsMountedProps = { | ||
rerender?: boolean; | ||
delay?: number; | ||
}; | ||
@@ -4,0 +5,0 @@ declare function useIsMounted(props?: UseIsMountedProps): (boolean | (() => boolean))[]; |
@@ -28,3 +28,3 @@ "use strict"; | ||
function useIsMounted(props = {}) { | ||
const { rerender = false } = props; | ||
const { rerender = false, delay = 0 } = props; | ||
const isMountedRef = (0, import_react.useRef)(false); | ||
@@ -34,4 +34,11 @@ const [isMounted, setIsMounted] = (0, import_react.useState)(false); | ||
isMountedRef.current = true; | ||
let timer = null; | ||
if (rerender) { | ||
setIsMounted(true); | ||
if (delay > 0) { | ||
timer = setTimeout(() => { | ||
setIsMounted(true); | ||
}, delay); | ||
} else { | ||
setIsMounted(true); | ||
} | ||
} | ||
@@ -43,2 +50,5 @@ return () => { | ||
} | ||
if (timer) { | ||
clearTimeout(timer); | ||
} | ||
}; | ||
@@ -45,0 +55,0 @@ }, [rerender]); |
{ | ||
"name": "@nextui-org/use-is-mounted", | ||
"version": "0.0.0-dev-v2-20230328184744", | ||
"version": "0.0.0-dev-v2-20230329200753", | ||
"description": "This hook can be used to render client-based components or run client logic", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
5969
97