@yamada-ui/utils
Advanced tools
Comparing version 1.6.1 to 1.6.2-dev-20241212094045
@@ -12,4 +12,4 @@ export { filterEmpty } from './array.js'; | ||
export { FlattenObjectOptions, assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject } from './object.js'; | ||
export { AsyncFnReturn, AsyncState, AsyncStateRetry, FunctionReturningPromise, MaybeRenderProp, PromiseType, UseIsMountedProps, UseIsMountedReturn, assignRef, createContext, createId, cx, findChild, findChildren, getValidChildren, includesChildren, isRefObject, isSomeElement, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useIsSsr, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.js'; | ||
export { AsyncFnReturn, AsyncState, AsyncStateRetry, FunctionReturningPromise, MaybeRenderProp, PromiseType, UseIsMountedProps, UseIsMountedReturn, UseMountedProps, UseMountedReturn, assignRef, createContext, createId, cx, findChild, findChildren, getValidChildren, includesChildren, isRefObject, isSomeElement, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useIsSsr, useMergeRefs, useMounted, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.js'; | ||
export { antonym, escape, toCamelCase, toKebabCase, toPascalCase, toTitleCase, transformSize } from './string.js'; | ||
import 'react'; |
@@ -164,2 +164,3 @@ "use strict"; | ||
useMergeRefs: () => useMergeRefs, | ||
useMounted: () => useMounted, | ||
useSafeLayoutEffect: () => useSafeLayoutEffect, | ||
@@ -1037,25 +1038,26 @@ useUnmountEffect: () => useUnmountEffect, | ||
} | ||
function useIsMounted({ | ||
var useIsMounted = useMounted; | ||
function useMounted({ | ||
delay = 0, | ||
rerender = false | ||
} = {}) { | ||
const isMountedRef = React.useRef(false); | ||
const [isMounted, setIsMounted] = React.useState(false); | ||
const mountedRef = React.useRef(false); | ||
const [mounted, setMounted] = React.useState(false); | ||
useSafeLayoutEffect(() => { | ||
isMountedRef.current = true; | ||
mountedRef.current = true; | ||
let timeoutId = null; | ||
if (rerender) { | ||
if (delay > 0) { | ||
timeoutId = setTimeout(() => setIsMounted(true), delay); | ||
timeoutId = setTimeout(() => setMounted(true), delay); | ||
} else { | ||
setIsMounted(true); | ||
setMounted(true); | ||
} | ||
} | ||
return () => { | ||
isMountedRef.current = false; | ||
if (rerender) setIsMounted(false); | ||
mountedRef.current = false; | ||
if (rerender) setMounted(false); | ||
if (timeoutId) clearTimeout(timeoutId); | ||
}; | ||
}, [delay, rerender]); | ||
return [React.useCallback(() => isMountedRef.current, []), isMounted]; | ||
return [React.useCallback(() => mountedRef.current, []), mounted]; | ||
} | ||
@@ -1199,3 +1201,3 @@ function useIsSsr() { | ||
const lastCallId = React.useRef(0); | ||
const [isMounted] = useIsMounted(); | ||
const [mounted] = useMounted(); | ||
const [state, setState] = React.useState(initialState); | ||
@@ -1209,3 +1211,3 @@ const callback = React.useCallback( | ||
(value) => { | ||
if (isMounted() && callId === lastCallId.current) | ||
if (mounted() && callId === lastCallId.current) | ||
setState({ loading: false, value }); | ||
@@ -1215,3 +1217,3 @@ return value; | ||
(error) => { | ||
if (isMounted() && callId === lastCallId.current) | ||
if (mounted() && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
@@ -1462,2 +1464,3 @@ return error; | ||
useMergeRefs, | ||
useMounted, | ||
useSafeLayoutEffect, | ||
@@ -1464,0 +1467,0 @@ useUnmountEffect, |
@@ -19,8 +19,20 @@ import * as React from 'react'; | ||
declare function useUnmountEffect(callback: () => void): void; | ||
interface UseIsMountedProps { | ||
/** | ||
* @deprecated Use `UseMountedProps` instead. | ||
*/ | ||
type UseIsMountedProps = UseMountedProps; | ||
/** | ||
* @deprecated Use `useMounted` instead. | ||
*/ | ||
declare const useIsMounted: typeof useMounted; | ||
/** | ||
* @deprecated Use `UseMountedReturn` instead. | ||
*/ | ||
type UseIsMountedReturn = UseMountedReturn; | ||
interface UseMountedProps { | ||
delay?: number; | ||
rerender?: boolean; | ||
} | ||
declare function useIsMounted({ delay, rerender, }?: UseIsMountedProps): [() => boolean, boolean]; | ||
type UseIsMountedReturn = ReturnType<typeof useIsMounted>; | ||
declare function useMounted({ delay, rerender, }?: UseMountedProps): [() => boolean, boolean]; | ||
type UseMountedReturn = ReturnType<typeof useMounted>; | ||
declare function useIsSsr(): boolean; | ||
@@ -104,2 +116,2 @@ declare function getValidChildren(children: React.ReactNode): React.ReactElement[]; | ||
export { type AsyncFnReturn, type AsyncState, type AsyncStateRetry, type FunctionReturningPromise, type MaybeRenderProp, type PromiseType, type UseIsMountedProps, type UseIsMountedReturn, assignRef, createContext, createId, cx, findChild, findChildren, getValidChildren, includesChildren, isRefObject, isSomeElement, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useIsSsr, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect }; | ||
export { type AsyncFnReturn, type AsyncState, type AsyncStateRetry, type FunctionReturningPromise, type MaybeRenderProp, type PromiseType, type UseIsMountedProps, type UseIsMountedReturn, type UseMountedProps, type UseMountedReturn, assignRef, createContext, createId, cx, findChild, findChildren, getValidChildren, includesChildren, isRefObject, isSomeElement, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useIsSsr, useMergeRefs, useMounted, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect }; |
@@ -54,2 +54,3 @@ "use strict"; | ||
useMergeRefs: () => useMergeRefs, | ||
useMounted: () => useMounted, | ||
useSafeLayoutEffect: () => useSafeLayoutEffect, | ||
@@ -105,25 +106,26 @@ useUnmountEffect: () => useUnmountEffect, | ||
} | ||
function useIsMounted({ | ||
var useIsMounted = useMounted; | ||
function useMounted({ | ||
delay = 0, | ||
rerender = false | ||
} = {}) { | ||
const isMountedRef = React.useRef(false); | ||
const [isMounted, setIsMounted] = React.useState(false); | ||
const mountedRef = React.useRef(false); | ||
const [mounted, setMounted] = React.useState(false); | ||
useSafeLayoutEffect(() => { | ||
isMountedRef.current = true; | ||
mountedRef.current = true; | ||
let timeoutId = null; | ||
if (rerender) { | ||
if (delay > 0) { | ||
timeoutId = setTimeout(() => setIsMounted(true), delay); | ||
timeoutId = setTimeout(() => setMounted(true), delay); | ||
} else { | ||
setIsMounted(true); | ||
setMounted(true); | ||
} | ||
} | ||
return () => { | ||
isMountedRef.current = false; | ||
if (rerender) setIsMounted(false); | ||
mountedRef.current = false; | ||
if (rerender) setMounted(false); | ||
if (timeoutId) clearTimeout(timeoutId); | ||
}; | ||
}, [delay, rerender]); | ||
return [React.useCallback(() => isMountedRef.current, []), isMounted]; | ||
return [React.useCallback(() => mountedRef.current, []), mounted]; | ||
} | ||
@@ -267,3 +269,3 @@ function useIsSsr() { | ||
const lastCallId = React.useRef(0); | ||
const [isMounted] = useIsMounted(); | ||
const [mounted] = useMounted(); | ||
const [state, setState] = React.useState(initialState); | ||
@@ -277,3 +279,3 @@ const callback = React.useCallback( | ||
(value) => { | ||
if (isMounted() && callId === lastCallId.current) | ||
if (mounted() && callId === lastCallId.current) | ||
setState({ loading: false, value }); | ||
@@ -283,3 +285,3 @@ return value; | ||
(error) => { | ||
if (isMounted() && callId === lastCallId.current) | ||
if (mounted() && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
@@ -332,2 +334,3 @@ return error; | ||
useMergeRefs, | ||
useMounted, | ||
useSafeLayoutEffect, | ||
@@ -334,0 +337,0 @@ useUnmountEffect, |
{ | ||
"name": "@yamada-ui/utils", | ||
"version": "1.6.1", | ||
"version": "1.6.2-dev-20241212094045", | ||
"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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
430581
5589
1