Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
How to return props from a Function component in React Native?

I am quite new to react/ReactNative. I am trying to return props from an array based on a particular error type.

This is how I am accessing the props returned through an array:

  const errorModalProps = IDV_USER_ERROR_STATES[errorType](handleExit, closeModalAndLogout);

This is the actual array which returns the props:

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>
        </>
    ),
  }),
};

I noticed that the geti18nClient is not getting initialized as it needs to be inside a function component. How can I refactor the array to act as a function component and return the props?

I tried doing something like this:

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>
                    </>
                ),
            });

    }

};

But getting this error :

S2366: Function lacks ending return statement and return type does not include 'undefined'.
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda