Hola, estaba tratando de agregar forwardRef a un componente secundario, pero obtuve lo siguiente al agregar forwardRef: TypeError: Component is not a function
El componente se define de la siguiente manera:
import React from 'react'; import { forwardRef } from 'react'; import { TextInputFocusEventData } from 'react-native'; import { NativeSyntheticEvent, StyleSheet } from 'react-native'; import { Input, InputProps } from 'react-native-elements'; import { Metrics, Colors } from '../../theme'; import Icons from '../Icons'; const CustomTextInput2 = forwardRef<TextInput, ICustomtextnputProps>((props, ref) => { const { name, required } = props; return ( <Input rightIcon={<Icons name="right" />} placeholder={name?.concat(required ? '*' : '')} inputContainerStyle={styles.inputContainer} inputStyle={styles.inputText} {...props} /> ) }); ....Aquí está el StackTrace:
ExceptionsManager.js:180 TypeError: Component is not a function This error is located at: in Unknown (at AddDetailsModal/index.tsx:67) in RCTView (at View.js:34) in View (at AddDetailsModal/index.tsx:66) in RCTView (at View.js:34) in View (at createAnimatedComponent.js:217) in AnimatedComponent (at createAnimatedComponent.js:278) in AnimatedComponentWrapper (at CustomModal/index.tsx:71) in RCTView (at View.js:34) in View (at createAnimatedComponent.js:217) in AnimatedComponent (at createAnimatedComponent.js:278) in AnimatedComponentWrapper (at TouchableOpacity.js:221) in TouchableOpacity (at TouchableOpacity.js:271) in Unknown (at CustomModal/index.tsx:70) in RCTView (at View.js:34) in View (at KeyboardAvoidingView.js:220) in KeyboardAvoidingView (at CustomModal/index.tsx:69) in RCTView (at View.js:34) in View (at AppContainer.js:107) in RCTView (at View.js:34) in View (at AppContainer.js:134) in AppContainer (at Modal.js:228) in RCTView (at View.js:34) in View (at Modal.js:249) in VirtualizedListContextResetter (at Modal.js:247) in RCTModalHostView (at Modal.js:234) in Modal (at CustomModal/index.tsx:63)¿Hay algo que deba cambiar para agregar un forwardRef a este componente?
después de envolver el componente por React.forwardRef y pasar la referencia del componente principal, ¡necesita volver a cargar la aplicación! Me enfrenté a eso ahora y vi el mismo mensaje de error y simplemente lo resolví recargando la aplicación.