use-debounce
use-debounce copied to clipboard
API of hooks are not documented
When i read the readme, i can't understand the API of hooks in the library.
For example, when i see
import React, { useState } from 'react';
import { useDebounce } from 'use-debounce';
export default function Input() {
const [text, setText] = useState('Hello');
const [value] = useDebounce(text, 1000);
return (
<div>
<input
defaultValue={'Hello'}
onChange={(e) => {
setText(e.target.value);
}}
/>
<p>Actual value: {text}</p>
<p>Debounce value: {value}</p>
</div>
);
}
it seems useDebounce(text, 1000);
returns array with multiple entities. First is debounced value and something more that is not documented.
I propose to fix this bug in documentation with one of
- add entities signatures with explanation
- explain explicitly that
useDebounce
returns array with only one element (if it is yours logic)
Even I also suggest doing this...
Hello @vitonsky , @devlopersabbir
The returning value is accessible from the useDebounce typing, which is 100% covered with TS type system.
Additionally for convenience we added documentation here https://github.com/xnimorz/use-debounce/commit/09b437c4d3d133e319846638a7bebb5b8b1fc5ba