@yamada-ui/utils
Advanced tools
Comparing version 0.0.0-dev-20231214105834 to 0.0.0-dev-20231220060707
@@ -5,3 +5,3 @@ export { Dict, Length, Merge, Path, Primitive, StringLiteral, Union } from './index.types.js'; | ||
export { funcAll, handlerAll, noop, runIfFunc } from './function.js'; | ||
export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionReturningPromise, MaybeRenderProp, PromiseType, PropGetter, RequiredPropGetter, assignRef, createContext, createId, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.js'; | ||
export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionReturningPromise, MaybeRenderProp, PromiseType, PropGetter, RequiredPropGetter, UseIsMountedProps, UseIsMountedReturn, assignRef, createContext, createId, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.js'; | ||
export { FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, platform, vendor } from './dom.js'; | ||
@@ -8,0 +8,0 @@ export { escape } from './string.js'; |
@@ -340,11 +340,27 @@ "use strict"; | ||
); | ||
var useIsMounted = () => { | ||
const isMounted = React.useRef(false); | ||
var useIsMounted = ({ | ||
rerender = false, | ||
delay = 0 | ||
} = {}) => { | ||
const isMountedRef = React.useRef(false); | ||
const [isMounted, setIsMounted] = React.useState(false); | ||
useSafeLayoutEffect(() => { | ||
isMounted.current = true; | ||
isMountedRef.current = true; | ||
let timeoutId = null; | ||
if (rerender) { | ||
if (delay > 0) { | ||
timeoutId = setTimeout(() => setIsMounted(true), delay); | ||
} else { | ||
setIsMounted(true); | ||
} | ||
} | ||
return () => { | ||
isMounted.current = false; | ||
isMountedRef.current = false; | ||
if (rerender) | ||
setIsMounted(false); | ||
if (timeoutId) | ||
clearTimeout(timeoutId); | ||
}; | ||
}, []); | ||
return isMounted; | ||
}, [delay, rerender]); | ||
return [React.useCallback(() => isMountedRef.current, []), isMounted]; | ||
}; | ||
@@ -426,3 +442,3 @@ var getValidChildren = (children) => React.Children.toArray(children).filter( | ||
const lastCallId = React.useRef(0); | ||
const isMounted = useIsMounted(); | ||
const [isMounted] = useIsMounted(); | ||
const [state, setState] = React.useState(initialState); | ||
@@ -436,3 +452,3 @@ const callback = React.useCallback( | ||
(value) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
if (isMounted() && callId === lastCallId.current) | ||
setState({ value, loading: false }); | ||
@@ -442,3 +458,3 @@ return value; | ||
(error) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
if (isMounted() && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
@@ -445,0 +461,0 @@ return error; |
@@ -26,3 +26,8 @@ import * as React from 'react'; | ||
declare const useUnmountEffect: (callback: () => void) => void; | ||
declare const useIsMounted: () => React.MutableRefObject<boolean>; | ||
type UseIsMountedProps = { | ||
rerender?: boolean; | ||
delay?: number; | ||
}; | ||
declare const useIsMounted: ({ rerender, delay, }?: UseIsMountedProps) => [() => boolean, boolean]; | ||
type UseIsMountedReturn = ReturnType<typeof useIsMounted>; | ||
declare const getValidChildren: (children: React.ReactNode) => React.ReactElement[]; | ||
@@ -93,2 +98,2 @@ declare const isValidElement: (child: any) => child is React.ReactNode; | ||
export { type AsyncFnReturn, type AsyncState, type AsyncStateRetry, type DOMAttributes, type FunctionReturningPromise, type MaybeRenderProp, type PromiseType, type PropGetter, type RequiredPropGetter, assignRef, createContext, createId, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect }; | ||
export { type AsyncFnReturn, type AsyncState, type AsyncStateRetry, type DOMAttributes, type FunctionReturningPromise, type MaybeRenderProp, type PromiseType, type PropGetter, type RequiredPropGetter, type UseIsMountedProps, type UseIsMountedReturn, assignRef, createContext, createId, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect }; |
@@ -92,11 +92,27 @@ "use strict"; | ||
); | ||
var useIsMounted = () => { | ||
const isMounted = React.useRef(false); | ||
var useIsMounted = ({ | ||
rerender = false, | ||
delay = 0 | ||
} = {}) => { | ||
const isMountedRef = React.useRef(false); | ||
const [isMounted, setIsMounted] = React.useState(false); | ||
useSafeLayoutEffect(() => { | ||
isMounted.current = true; | ||
isMountedRef.current = true; | ||
let timeoutId = null; | ||
if (rerender) { | ||
if (delay > 0) { | ||
timeoutId = setTimeout(() => setIsMounted(true), delay); | ||
} else { | ||
setIsMounted(true); | ||
} | ||
} | ||
return () => { | ||
isMounted.current = false; | ||
isMountedRef.current = false; | ||
if (rerender) | ||
setIsMounted(false); | ||
if (timeoutId) | ||
clearTimeout(timeoutId); | ||
}; | ||
}, []); | ||
return isMounted; | ||
}, [delay, rerender]); | ||
return [React.useCallback(() => isMountedRef.current, []), isMounted]; | ||
}; | ||
@@ -178,3 +194,3 @@ var getValidChildren = (children) => React.Children.toArray(children).filter( | ||
const lastCallId = React.useRef(0); | ||
const isMounted = useIsMounted(); | ||
const [isMounted] = useIsMounted(); | ||
const [state, setState] = React.useState(initialState); | ||
@@ -188,3 +204,3 @@ const callback = React.useCallback( | ||
(value) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
if (isMounted() && callId === lastCallId.current) | ||
setState({ value, loading: false }); | ||
@@ -194,3 +210,3 @@ return value; | ||
(error) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
if (isMounted() && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
@@ -197,0 +213,0 @@ return error; |
{ | ||
"name": "@yamada-ui/utils", | ||
"version": "0.0.0-dev-20231214105834", | ||
"version": "0.0.0-dev-20231220060707", | ||
"description": "Yamada UI utils", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
313702
3763