-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: enhance TS types, add missed export explicit type definition
- Loading branch information
Showing
31 changed files
with
95 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { useEffect } from 'react' | ||
import { createDebouncedEffect } from '../utils/create-effect/debounced' | ||
|
||
import type { UseDebouncedEffect } from '../utils/create-effect/debounced' | ||
import type { DebounceOptions } from '../utils/debounce' | ||
|
||
export interface UseDebouncedEffectOptions extends DebounceOptions {} | ||
|
||
/** | ||
* A React Hook like [React.useEffect](https://react.dev/reference/react/useEffect), but debounced. | ||
*/ | ||
export const useDebouncedEffect = createDebouncedEffect(useEffect) | ||
export const useDebouncedEffect: UseDebouncedEffect<never> = createDebouncedEffect(useEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { useEffect } from 'react' | ||
import { createDeepCompareEffect } from '../utils/create-effect/deep-compare' | ||
|
||
import type { UseDeepCompareEffect } from '../utils/create-effect/deep-compare' | ||
|
||
/** | ||
* A React Hook like [React.useEffect](https://react.dev/reference/react/useEffect), but with [deep comparison](https://github.com/sheinsight/react-use/blob/main/src/utils/equal.ts#L29) of dependencies. | ||
*/ | ||
export const useDeepCompareEffect = createDeepCompareEffect(useEffect) | ||
export const useDeepCompareEffect: UseDeepCompareEffect<never> = createDeepCompareEffect(useEffect) |
5 changes: 4 additions & 1 deletion
5
packages/react-use/src/use-deep-compare-layout-effect/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { useIsomorphicLayoutEffect } from '../use-isomorphic-layout-effect' | ||
import { createDeepCompareEffect } from '../utils/create-effect/deep-compare' | ||
|
||
import type { UseDeepCompareEffect } from '../utils/create-effect/deep-compare' | ||
|
||
/** | ||
* Same as [useDeepCompareEffect](https://sheinsight.github.io/react-use/reference/use-deep-compare-effect), but use `useLayoutEffect` instead of `useEffect`. | ||
*/ | ||
export const useDeepCompareLayoutEffect = createDeepCompareEffect(useIsomorphicLayoutEffect) | ||
export const useDeepCompareLayoutEffect: UseDeepCompareEffect<never> = | ||
createDeepCompareEffect(useIsomorphicLayoutEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { useEffect } from 'react' | ||
import { createEffectOnce } from '../utils/create-effect/once' | ||
|
||
import type { UseEffectOnce } from '../utils/create-effect/once' | ||
|
||
/** | ||
* A React Hook like [React.useEffect](https://react.dev/reference/react/useEffect) but only run once, with more **semantic** name. | ||
* | ||
* It's merely an alias to `useEffect` with an empty dependency array. | ||
*/ | ||
export const useEffectOnce = createEffectOnce(useEffect) | ||
export const useEffectOnce: UseEffectOnce<never> = createEffectOnce(useEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { useEffect, useLayoutEffect } from 'react' | ||
import { isClient } from '../utils/basic' | ||
|
||
export type UseEffect = typeof useEffect | ||
|
||
/** | ||
* A React Hook that will automatically use [React.useLayoutEffect](https://react.dev/reference/react/useLayoutEffect) in client side, | ||
* | ||
* and [React.useEffect](https://react.dev/reference/react/useEffect) in server side to avoid the warning of `useLayoutEffect` in Server-side Rendering (SSR). | ||
*/ | ||
export const useIsomorphicLayoutEffect = isClient ? useLayoutEffect : useEffect | ||
export const useIsomorphicLayoutEffect: UseEffect = isClient ? useLayoutEffect : useEffect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { useIsomorphicLayoutEffect } from '../use-isomorphic-layout-effect' | ||
import { createEffectOnce } from '../utils/create-effect/once' | ||
|
||
import type { UseEffectOnce } from '../utils/create-effect/once' | ||
|
||
/** | ||
* A React Hook that like <Link to="/reference/use-effect-once">`useEffectOnce`</Link> but use <Link to="/reference/use-isomorphic-layout-effect">`useIsomorphicLayoutEffect`</Link> under the hood. | ||
*/ | ||
export const useLayoutEffectOnce = createEffectOnce(useIsomorphicLayoutEffect) | ||
export const useLayoutEffectOnce: UseEffectOnce<never> = createEffectOnce(useIsomorphicLayoutEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { useEffect } from 'react' | ||
import { createThrottledEffect } from '../utils/create-effect/throttled' | ||
|
||
import type { UseThrottledEffect } from '../utils/create-effect/throttled' | ||
import type { ThrottleOptions } from '../utils/throttle' | ||
|
||
export interface UseThrottledEffectOptions extends ThrottleOptions {} | ||
|
||
/** | ||
* A React Hook like [React.useEffect](https://react.dev/reference/react/useEffect), but throttled. | ||
*/ | ||
export const useThrottledEffect = createThrottledEffect(useEffect) | ||
export const useThrottledEffect: UseThrottledEffect<never> = createThrottledEffect(useEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { useEffect } from 'react' | ||
import { createUpdateEffect } from '../utils/create-effect/update' | ||
|
||
import type { UseUpdateEffect } from '../utils/create-effect/update' | ||
|
||
/** | ||
* A React Hook like [React.useEffect](https://react.dev/reference/react/useEffect), but ignore the first invocation on mount. | ||
*/ | ||
export const useUpdateEffect = createUpdateEffect(useEffect) | ||
export const useUpdateEffect: UseUpdateEffect<never> = createUpdateEffect(useEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { useIsomorphicLayoutEffect } from '../use-isomorphic-layout-effect' | ||
import { createUpdateEffect } from '../utils/create-effect/update' | ||
|
||
import type { UseUpdateEffect } from '../utils/create-effect/update' | ||
|
||
/** | ||
* A React Hook like [React.useLayoutEffect](https://react.dev/reference/react/useLayoutEffect), | ||
* but ignore the first invocation on mount, and use `useIsomorphicLayoutEffect` under the hood to support Server-side Rendering (SSR). | ||
*/ | ||
export const useUpdateLayoutEffect = createUpdateEffect(useIsomorphicLayoutEffect) | ||
export const useUpdateLayoutEffect: UseUpdateEffect<never> = createUpdateEffect(useIsomorphicLayoutEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import type { EffectCallback } from 'react' | ||
import type { ExtendedReactEffect } from '../basic' | ||
|
||
export function createEffectOnce<T = unknown>(effect: ExtendedReactEffect<T>) { | ||
return (callback: EffectCallback, ...args: T[]) => { | ||
export type UseEffectOnce<T> = (callback: EffectCallback, ...args: T[]) => void | ||
|
||
export function createEffectOnce<T = unknown>(effect: ExtendedReactEffect<T>): UseEffectOnce<T> { | ||
return (callback: EffectCallback, ...args: T[]): void => { | ||
effect(callback, [], ...args) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.