Skip to content

Commit 24fc538

Browse files
authored
Merge pull request #168 from xnimorz/yarn_to_npm
upd readme
2 parents b928077 + 1228b30 commit 24fc538

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
</a>
2020
</div>
2121

22+
# useDebounce, useDebouncedCallback & useThrottledCallback
23+
24+
React libraries for debouncing without tears!
25+
26+
- Small size < 1 Kb
27+
- Compatible with underscore / lodash impl — learn once, use everywhere
28+
- Server-rendering friendly!
29+
2230
## Features
2331

2432
- [classic debounced callback](#debounced-callbacks)
@@ -47,9 +55,9 @@ Debounce HTTP request with `leading` param: https://codesandbox.io/s/cache-examp
4755

4856
Simple usage: https://codesandbox.io/s/x0jvqrwyq
4957

50-
Combining with native event listeners: https://codesandbox.io/s/32yqlyo815
58+
Combining with native event listeners: https://codesandbox.io/s/32yqlyo815
5159

52-
Cancelling, maxWait and memoization: https://codesandbox.io/s/4wvmp1xlw4
60+
Cancelling, maxWait and memoization: https://codesandbox.io/s/4wvmp1xlw4
5361

5462
HTTP requests: https://codesandbox.io/s/use-debounce-callback-http-y1h3m6
5563

@@ -109,7 +117,10 @@ function Input({ defaultValue }) {
109117
// you should use `e => debounced(e.target.value)` as react works with synthetic events
110118
return (
111119
<div>
112-
<input defaultValue={defaultValue} onChange={(e) => debounced(e.target.value)} />
120+
<input
121+
defaultValue={defaultValue}
122+
onChange={(e) => debounced(e.target.value)}
123+
/>
113124
<p>Debounced value: {value}</p>
114125
</div>
115126
);
@@ -216,7 +227,10 @@ function Input({ defaultValue }) {
216227
// you should use `e => debounced(e.target.value)` as react works with synthetic events
217228
return (
218229
<div>
219-
<input defaultValue={defaultValue} onChange={(e) => debounced(e.target.value)} />
230+
<input
231+
defaultValue={defaultValue}
232+
onChange={(e) => debounced(e.target.value)}
233+
/>
220234
<p>Debounced value: {value}</p>
221235
<button onClick={debounced.cancel}>Cancel Debounce cycle</button>
222236
</div>
@@ -252,7 +266,12 @@ function InputWhichFetchesSomeData({ defaultValue, asyncFetchData }) {
252266
[debounced]
253267
);
254268

255-
return <input defaultValue={defaultValue} onChange={(e) => debounced(e.target.value)} />;
269+
return (
270+
<input
271+
defaultValue={defaultValue}
272+
onChange={(e) => debounced(e.target.value)}
273+
/>
274+
);
256275
}
257276
```
258277

@@ -264,7 +283,10 @@ function InputWhichFetchesSomeData({ defaultValue, asyncFetchData }) {
264283
import React, { useCallback } from 'react';
265284

266285
function Component({ text }) {
267-
const debounced = useDebouncedCallback(useCallback(() => {}, []), 500);
286+
const debounced = useDebouncedCallback(
287+
useCallback(() => {}, []),
288+
500
289+
);
268290

269291
expect(debounced.isPending()).toBeFalsy();
270292
debounced();
@@ -316,7 +338,7 @@ You can provide additional options as a third argument to both `useDebounce` and
316338
| maxWait | - | Describes the maximum time func is allowed to be delayed before it's invoked | https://github.com/xnimorz/use-debounce#cancel-maxwait-and-memoization |
317339
| leading | - | This param will execute the function once immediately when called. Subsequent calls will be debounced until the timeout expires. | https://github.com/xnimorz/use-debounce#leading-calls |
318340
| trailing | true | This param executes the function after timeout. | https://github.com/xnimorz/use-debounce#leading-calls |
319-
| equalityFn | (prev, next) => prev === next | [useDebounce ONLY] Comparator function which shows if timeout should be started | |
341+
| equalityFn | (prev, next) => prev === next | [useDebounce ONLY] Comparator function which shows if timeout should be started | |
320342

321343
## useThrottledCallback
322344

0 commit comments

Comments
 (0)