-
Notifications
You must be signed in to change notification settings - Fork 116
Document usage of debounced setter in README #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Added section on using the debounced setter with example.
xnimorz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's needed. If you want to add information of a setter inside a tuple, I suggest adding it right after the example of usage.
| import React from 'react'; | ||
| import { useDebounce } from 'use-debounce'; | ||
|
|
||
| export default function Input() { | ||
| const [state, setState] = useDebounce('', 300); | ||
|
|
||
| return ( | ||
| <div> | ||
| <input onChange={(e) => setState(e.target.value)} /> | ||
| <p>Debounced value: {state}</p> | ||
| </div> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same example exist right above the added section.
I don't think repetition is needed here
|
|
||
| ### Using the debounced setter | ||
|
|
||
| In addition to getting the debounced value, you can destructure a second element which is a debounced setter function. This allows you to use `useDebounce` without needing a separate state variable for the input value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not "in addition". It's main feature, explained above.
If you want to add additional information, let's put simple inside this section https://github.com/xnimorz/use-debounce/blob/master/README.md#simple-values-debouncing
useDebounce returns a tuple with 2 arguments: debounced value and setter.
| } | ||
| ``` | ||
|
|
||
| This is particularly useful when you don't need to track the immediate input value and only care about the debounced result. The debounced setter also provides additional methods like `cancel`, `isPending`, and `flush` for advanced control. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's covered below.
Added section on using the debounced setter with example.
Currently this is not documented and AI is complaining when using this because when looking at the documentation it does not see it anywhere