-
Notifications
You must be signed in to change notification settings - Fork 67
feat: add ref support to Scanner component #143
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { RefCallback, RefObject } from 'react'; | ||
|
||
export function mergeRefs<T>(...refs: Array<RefObject<T> | RefCallback<T> | null | undefined>): RefCallback<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The signature excludes MutableRefObject and uses RefObject, which makes passing useRef refs (e.g., MutableRefObject<HTMLVideoElement | null>) a type error. Switch to React.Ref (or include MutableRefObject<T | null>) so both object and callback refs are accepted. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
return (value) => { | ||
for (const ref of refs) { | ||
if (ref == null) { | ||
continue; | ||
} | ||
|
||
if (typeof ref === 'function') { | ||
ref(value); | ||
continue; | ||
} | ||
|
||
(ref as RefObject<T | null>).current = value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RefObject has a readonly current; assigning to .current here is a type error. Cast to MutableRefObject<T | null> (or narrow with an appropriate type guard) before assignment: (ref as MutableRefObject<T | null>).current = value. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current mergeRefs signature (Array<RefObject | RefCallback ...>), videoRef (MutableRefObject<HTMLVideoElement | null>) is not assignable, producing a type error. This will be resolved by updating mergeRefs to accept React.Ref (or include MutableRefObject<T | null>) as suggested.
Copilot uses AI. Check for mistakes.