Skip to content

Commit

Permalink
add new hook
Browse files Browse the repository at this point in the history
  • Loading branch information
edelgarat committed Jan 30, 2024
1 parent b84bcd0 commit 8aa7f9b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@worksolutions/react-utils",
"private": false,
"version": "2.2.1",
"version": "2.2.2",
"description": "",
"types": "dist/esm/index.d.ts",
"main": "dist/cjs/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./special";
export * from "./useAsyncFn";
export * from "./useChildrenMeasure";
export * from "./useDebouncedInput";
export * from "./useDebouncedValue";
export * from "./useMeasure";
export * from "./useTimer";
export * from "./useStickyEffectDetector";
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/useDebouncedValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { useState } from "react";

import { useDebounceRef } from "./common";

export function useDebouncedValue<VALUE>(value: VALUE, debounceTime: number) {
const [resultValue, setResultValue] = useState(value);
const handleDebouncedChangeRef = useDebounceRef(debounceTime, setResultValue);
React.useEffect(() => handleDebouncedChangeRef.current(value), [handleDebouncedChangeRef, value]);
return resultValue;
}

0 comments on commit 8aa7f9b

Please sign in to comment.