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

136
Visualizações
Can't render a toast message when error is triggered on a field using react-hook-forms

I am using react-native and react-hook-form with react-native-toast-notifications to display errors in my form. I want to trigger a toast.show('my custom message') if there's a particular validation error on the field, the component looks like this:

export default function RegisterScreen(props) {
  // we initialize Toasts
  const toast = useToast();

  // loading state
  const [loading, setLoading] = useState(false);

  // we manage the errors
  const [newError, setNewError] = useState();

  // we setup the use of dispatch
  const dispatch = useDispatch();

  // setup of our form
  const {
    control,
    handleSubmit,
    formState: { errors },
  } = useForm();

  // our submit handler
  const onSubmit = async data => {
    setLoading(true);
    setNewError(null);
    console.log(data);
    try {
      await dispatch(authActions.signup(data.email, data.password));
    } catch (err) {
      toast.show(err.message, { type: 'danger', duration: 4000 });
      setLoading(false);
    }
  };
 // returning the view
  return (
    <>
      <ScrollView>
        {errors.email && toast.show('email invalid')}
        <Controller
          control={control}
          rules={{
            required: true,
          }}
          render={({ field: { onChange, onBlur, value } }) => (
            <Input
              placeholder='Solo emails válidos'
              onBlur={onBlur}
              onChangeText={onChange}
              value={value}
              error={errors.email}
              name={t('auth:email')}
              autoFocus
              keyboardType='email-address'
              autoComplete='email'
              autoCorrect={false}
              returnKeyType='next'
              textContentType='emailAddress'
            />
          )}
          name='email'
        />
</>
  );
}

By triggering the error.email I want to render a Toast, but it tells me "Error: Text strings must be rendered within a component.". I tried also {error.email && ()=> toast.show('my message') and it doesn't work also.

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