Soy bastante nuevo en reaccionar/ReactNative. Estoy tratando de devolver accesorios de una matriz en función de un tipo de error en particular.
Así es como accedo a los accesorios devueltos a través de una matriz:
const errorModalProps = IDV_USER_ERROR_STATES[errorType](handleExit, closeModalAndLogout);Esta es la matriz real que devuelve los accesorios:
const t = geti18nClient(); export const IDV_USER_ERROR_STATES: { [key: string]: (onPress?: () => Promise<void>, onSecondaryPress?: () => Promise<void>) => IErrorModalProps; } = { [IDVValidationErrorTypes.AGE_REQUIREMENT_NOT_MET]: onPress => ({ svg: 'AgeLimitError', // new svg inclusion title: t('ageLimitError.title'), description: t('ageLimitError.description'), controls: ( <> <Button onPress={onPress}>{t('common:logout')}</Button> </> ), }), [IDVValidationErrorTypes.NON_CANADIAN_PASSPORT]: (onPress, onSecondaryPress) => ({ svg: 'AgeLimitError', // new svg inclusion title: t('ageLimitError.title'), description: t('ageLimitError.description'), controls: ( <> <Button mb={10} onPress={onPress}> {t('common:tryAgain')} </Button> <Button variant="secondary" onPress={onSecondaryPress}> {t('common:logout')} </Button> </> ), }), }; Noté que geti18nClient no se inicializa, ya que debe estar dentro de un componente de función. ¿Cómo puedo refactorizar la matriz para que actúe como un componente de función y devolver los accesorios?
Intenté hacer algo como esto:
const returnIDVProps = (key: string): (onPress?: () => Promise<void>, onSecondaryPress?: () => Promise<void>) => IErrorModalProps => { const t = geti18nClient(); switch (key) { case IDVValidationErrorTypes.AGE_REQUIREMENT_NOT_MET: return (onPress, onSecondaryPress) => ({ svg: 'AgeLimitError', // new svg inclusion title: t('ageLimitError.title'), description: t('ageLimitError.description'), controls: ( <> <Button mb={10} onPress={onPress}> {t('common:tryAgain')} </Button> <Button variant="secondary" onPress={onSecondaryPress}> {t('common:logout')} </Button> </> ), }); } };Pero obteniendo este error:
S2366: Function lacks ending return statement and return type does not include 'undefined'.