Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda