Skip to content

Should useRef's TypeScript declaration also allow it to be "null"? #2268

@rdmurphy

Description

@rdmurphy

I noticed a subtle difference between Preact's useRef declaration and React's — React's useRef type has an overload that allows for the given <T> or null, which is what you'd expect to be viable when you use useRef as directed by passing in null on initialization.

However Preact's type for useRef doesn't account for this, which means it throws a type error immediately when it sees the null you initially passed.

Is this something that was intentionally excluded or was it perhaps an oversight?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions