Skip to content

Suggest updating userRef type to allow null for compatibility with useRef #39

@jiangtaste

Description

@jiangtaste

Hi, thanks for the great project!

I’d like to suggest a small but meaningful type improvement to the userRef prop.

Currently, it’s typed as:
userRef?: React.MutableRefObject<HTMLDivElement>;

However, this leads to a TypeScript error when using useRef in the typical React way:
const ref = useRef<HTMLDivElement | null>(null); // Error: Type 'MutableRefObject<HTMLDivElement | null>' is not assignable to type 'MutableRefObject<HTMLDivElement>'

To fix this, and to support the standard usage pattern where refs are initialized as null before mounting, I suggest changing the type to:
userRef?: React.MutableRefObject<HTMLDivElement | null>;

This makes the prop fully compatible with React’s recommended useRef pattern and prevents unnecessary type casting or unsafe assertions.

Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions