use-debounce icon indicating copy to clipboard operation
use-debounce copied to clipboard

API of hooks are not documented

Open vitonsky opened this issue 1 year ago • 1 comments

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)

vitonsky avatar Jan 23 '24 15:01 vitonsky

Even I also suggest doing this...

devlopersabbir avatar Jan 25 '24 17:01 devlopersabbir

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

xnimorz avatar Jun 07 '24 18:06 xnimorz