Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
thebuilder committed Aug 5, 2024
1 parent a5e1e99 commit b889fb0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ debouncedCallback("Hello");
debouncedCallback("World"); // Will only log "World" after 500ms
```

The `debouncedCallback` also contains a few methods, that can be useful:

- `flush`: Call the callback immediately, and cancel the debounce.
- `cancel`: Cancel the debounce, and the callback will never be called.
- `isPending`: Check if the callback is waiting to be called.

You can use them like this:

```tsx
const debouncedCallback = useDebouncedCallback((value: string) => {
console.log(value);
}, 500);

debouncedCallback("Hello");
debouncedCallback.isPending(); // true
debouncedCallback.flush(); // Logs "Hello"
debouncedCallback("world");
debouncedCallback.cancel(); // Will never log "world"
```

### `useElementSize`

Monitor the size of an element, and return the size object.
Expand Down

0 comments on commit b889fb0

Please sign in to comment.