Skip to content

Commit

Permalink
fix(utilities): resolve assignRef TypeScript ref assignment issue (#3098
Browse files Browse the repository at this point in the history
)

* fix(utilities): resolve assignRef TypeScript ref assignment issue

* chore(changeset): revise changeset message

---------

Co-authored-by: WK Wong <[email protected]>
  • Loading branch information
Gaic4o and wingkwong committed Jun 15, 2024
1 parent 255c641 commit b9bb06f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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
---

refactored the assignRef function to remove @ts-ignore and properly handle reference assignment using MutableRefObject
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;
} catch (error) {
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
}
Expand Down

0 comments on commit b9bb06f

Please sign in to comment.