xnimorz/use-debounce

Bad example for useDebouncedCallback in README

TonisPiip opened this issue · 8 comments

in the readme example of useDebouncedCallback you have:

 const debounced = useDebouncedCallback(
    // function
    (value) => {
      setValue(value);
    },
    // delay in ms
    1000
  );

But it's returning an array, so it really should be

const [debounced] = useDebouncedCallback(

Hi @TonisPiip
useDebouncedCallback returns an object \ function. You can check the example here: https://codesandbox.io/s/x0jvqrwyq

So the Readme shows the right information.

I am on the latest release and @TonisPiip is right. I was able to get the function only as an array. Attaching screenshot:

image

It looks pretty odd (like you received an old release somehow), as this is an API from the old major versions.

I checked it by installing the latest version 6.0.1:
image

Can you check the version in node_modules/use-debounce/package.json and the content inside .d.ts files in node_modules/use-debounce/esm/useDebouncedCallback.d.ts and node_modules/use-debounce/lib/useDebouncedCallback.d.ts?

This information should help me to understand your issue

I have "use-debounce": "3.4.2" So yes, it's an older version.

Perhaps the npm release version isn't same as master branch?

The last version according to the npm is https://www.npmjs.com/package/use-debounce
Master branch represents usually the latest version in this repo.

Feel free to reopen this issue if you still have any problems.

I'm using 6.0.1 and having the same issue as @TonisPiip, the TypeScript definition is fine but the actual code is returning an array.

UPDATE: fixed after removed node_modules and reinstalled packages.