Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc]: add jsdoc for hook useDebouncedValue #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/hooks/useDebouncedValue/useDebouncedValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,35 @@ import { debounce } from '@/utils/helpers';
// усложняем ли хуки value и state

interface UseDebouncedValueOptions {
/** The maximum time the debounce function will wait before being invoked */
maxWait?: number;
}

export type UseDocumentTitleReturn<Value> = [
/** The debounced state value */
state: Value,

/** Function to update the state value */
debouncedSetState: (value: Value) => void
];

/**
* @name useDebouncedValue
* @description - Hook that returns a debounced value and a function to update it
*
* @param {Value} value - The value to be debounced
* @param {number} delay - The delay in milliseconds for debouncing
* @param {UseDebouncedValueOptions} [options] - Optional configurations for debouncing
* @returns {UseDocumentTitleReturn} - Returns the debounced value and a function to update the state
*
* @example
* const [debouncedValue, setDebouncedValue] = useDebouncedValue(value, 300);
*/
export const useDebouncedValue = <Value>(
value: Value,
delay: number,
options?: UseDebouncedValueOptions
) => {
): UseDocumentTitleReturn<Value> => {
console.log('@', options);
const previousValueRef = React.useRef(value);
const [state, setState] = React.useState(value);
Expand Down