@@ -32,7 +32,9 @@ class Hyperlink extends Component<HyperlinkProps, HyperlinkState> {
3232 }
3333
3434 render ( ) {
35- const { ...viewProps } = this . props ;
35+ // Avoid spreading React special props such as `key` or `ref`
36+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37+ const { key : _key , ref : _ref , ...viewProps } = this . props as any ;
3638
3739 // If no link handlers or styles, just render children as-is
3840 if (
@@ -96,6 +98,8 @@ class Hyperlink extends Component<HyperlinkProps, HyperlinkState> {
9698
9799 // Create component props (ref and key are React-specific and not in TextProps)
98100 const componentProps = component . props as TextProps ;
101+ delete ( componentProps as { ref ?: unknown } ) . ref ;
102+ delete ( componentProps as { key ?: unknown } ) . key ;
99103
100104 try {
101105 this . state . linkifyIt
@@ -157,11 +161,9 @@ class Hyperlink extends Component<HyperlinkProps, HyperlinkState> {
157161 let { props : { children } = { children : undefined } } = component || { } ;
158162 if ( ! children ) return component ;
159163
160- const componentProps = {
161- ...component . props ,
162- ref : undefined ,
163- key : undefined ,
164- } ;
164+ const componentProps = component . props as TextProps ;
165+ delete ( componentProps as { ref ?: unknown } ) . ref ;
166+ delete ( componentProps as { key ?: unknown } ) . key ;
165167
166168 return React . cloneElement (
167169 component ,
@@ -214,13 +216,17 @@ export default class extends Component<HyperlinkProps> {
214216
215217 render ( ) {
216218 const onPress = this . props . onPress ?? this . handleLink ;
219+ // Do not forward `key`/`ref` to the inner `Hyperlink` to avoid
220+ // React warning about spreading a props object that contains `key`.
221+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
222+ const { key : _key , ref : _ref , ...rest } = this . props as any ;
217223 return this . props . linkDefault ? (
218224 < Hyperlink
219- { ...this . props }
225+ { ...rest }
220226 onPress = { onPress }
221227 />
222228 ) : (
223- < Hyperlink { ...this . props } />
229+ < Hyperlink { ...rest } />
224230 ) ;
225231 }
226232}
0 commit comments