Skip to content
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

useDefault types #292

Open
DerHumm3l opened this issue Apr 6, 2024 · 0 comments
Open

useDefault types #292

DerHumm3l opened this issue Apr 6, 2024 · 0 comments

Comments

@DerHumm3l
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant