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

fix(utilities): resolve assignRef TypeScript ref assignment issue #3098

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-oranges-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/react-utils": patch
---

WHAT: refactored the signRef function to remove @ts-ignore and properly handle reference assignment using MutableRefObject
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions packages/utilities/react-utils/src/refs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";
import {isFunction} from "@nextui-org/shared-utils";
import {MutableRefObject} from "react";

export type ReactRef<T> = React.RefObject<T> | React.MutableRefObject<T> | React.Ref<T>;

Expand All @@ -19,8 +20,7 @@ export function assignRef<T = any>(ref: ReactRef<T> | undefined, value: T) {
}

try {
// @ts-ignore
ref.current = value;
(ref as MutableRefObject<T>).current = value;
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
}
Expand Down
Loading