use-debounce-hook-web 0.1.9 → 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 +97 -1
  2. package/package.json +5 -2
package/README.md CHANGED
@@ -5,4 +5,100 @@ A lightweight, production-ready debounce hook for React applications. Designed t
5
5
  ## Install
6
6
  ```markdown
7
7
  npm i use-debounce-hook-web
8
- ```
8
+ ```
9
+
10
+
11
+ ## Basic Usage
12
+ ```js
13
+ useDebounce(value, delay)
14
+ ```
15
+
16
+ ```js
17
+ import { useDebounce } from 'use-debounce-hook-web';
18
+ import { useState } from 'react';
19
+
20
+ const SearchInput = () => {
21
+ const [value, setValue] = useState('');
22
+
23
+ const debouncedValue = useDebounce(value, 500);
24
+
25
+ return (
26
+ <input
27
+ value={value}
28
+ onChange={(e) => setValue(e.target.value)}
29
+ placeholder="Search..."
30
+ />
31
+ );
32
+ };
33
+
34
+ export default SearchInput;
35
+ ```
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
+
87
+
88
+ ## Options
89
+ | Property | Type | Description |
90
+ | -------- | ------- | ----------------------------------------- |
91
+ | value | any | The value to debounce |
92
+ | delay | number | Debounce delay in milliseconds |
93
+ | leading | boolean | Execute immediately on first trigger |
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.9",
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",