usehooks icon indicating copy to clipboard operation
usehooks copied to clipboard

useDefault types

Open DerHumm3l opened this issue 10 months ago • 0 comments

Hi, I used the useDefault hook in my project with typescript in strict mode and had a little issue with the types returned by useDefault.

If I write the following code

import { useDefault } from "@uidotdev/usehooks";

function getInitialFoo(): string | null {
  return null;
}

export function App() {
  const initalFoo = getInitialFoo();
  const [foo, setFoo] = useDefault(initalFoo, "default");
}

then foo is string | null.

image

I would expect foo to be string since the passed default value is a string. So I was wondering if the types for useDefault are correct? Or am I missing something?

DerHumm3l avatar Apr 06 '24 15:04 DerHumm3l