use-debounce-hook-web 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +66 -1
  2. package/package.json +5 -2
package/README.md CHANGED
@@ -8,6 +8,11 @@ npm i use-debounce-hook-web
8
8
  ```
9
9
 
10
10
 
11
+ ## Basic Usage
12
+ ```js
13
+ useDebounce(value, delay)
14
+ ```
15
+
11
16
  ```js
12
17
  import { useDebounce } from 'use-debounce-hook-web';
13
18
  import { useState } from 'react';
@@ -29,6 +34,56 @@ const SearchInput = () => {
29
34
  export default SearchInput;
30
35
  ```
31
36
 
37
+ ## Advanced Usage
38
+ ```js
39
+ useDebounce(value, delay, options)
40
+ ```
41
+
42
+ ```js
43
+ const debouncedValue = useDebounce(value, 500, {
44
+ immediate: true,
45
+ maxWait: 2000
46
+ });
47
+ ```
48
+ ```js
49
+ const debouncedValue = useDebounce(value, 500, {
50
+ maxWait: 2000
51
+ });
52
+ ```
53
+
54
+ ```js
55
+ import { useEffect, useState } from "react";
56
+ import { useDebounce } from "react-use-debounce";
57
+
58
+ function SearchUsers() {
59
+ const [query, setQuery] = useState("");
60
+ const debouncedQuery = useDebounce(query, 500, {
61
+ immediate: true,
62
+ maxWait: 2000
63
+ });
64
+
65
+ useEffect(() => {
66
+ if (!debouncedQuery) return;
67
+
68
+ fetch(`https://api.example.com/users?q=${debouncedQuery}`)
69
+ .then(res => res.json())
70
+ .then(data => console.log(data));
71
+ }, [debouncedQuery]);
72
+
73
+ return (
74
+ <input
75
+ placeholder="Search users..."
76
+ value={query}
77
+ onChange={(e) => setQuery(e.target.value)}
78
+ />
79
+ );
80
+ }
81
+
82
+ export default SearchUsers;
83
+
84
+ ```
85
+
86
+
32
87
 
33
88
  ## Options
34
89
  | Property | Type | Description |
@@ -36,4 +91,14 @@ export default SearchInput;
36
91
  | value | any | The value to debounce |
37
92
  | delay | number | Debounce delay in milliseconds |
38
93
  | leading | boolean | Execute immediately on first trigger |
39
- | maxWait | number | Maximum wait time before forced execution |
94
+ | maxWait | number | Maximum wait time before forced execution |
95
+
96
+
97
+ ## More Use Options
98
+ | Use Case | immediate | maxWait |
99
+ | ------------- | --------- | ------- |
100
+ | Search UX | ✅ Yes | ✅ Yes |
101
+ | Auto-save | ❌ No | ✅ Yes |
102
+ | Filtering | ❌ No | ❌ No |
103
+ | Resize events | ❌ No | ❌ No |
104
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-debounce-hook-web",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "description": "A simple and reusable debounce hook for React",
5
5
  "main": "src/index.js",
6
6
  "publishConfig": {
@@ -15,7 +15,10 @@
15
15
  "debounce",
16
16
  "hook",
17
17
  "react-hooks",
18
- "useDebounce"
18
+ "useDebounce",
19
+ "useEffect",
20
+ "nextjs",
21
+ "frontend"
19
22
  ],
20
23
  "author": "Yogesh Negi",
21
24
  "license": "MIT",