1 year ago
#382571
dave
react native - how to display error authentication message on app screen
I have a registration screen, in which when I fill out the input form with an existing details and submit, an error message 'the email has already been taken', I want the message
that show in the cmd
to display on my registration screen.
registration.js screen
const handleSubmit = async ({ name, email, password } ) => {
await axios.post(userRegister,
{
name,
email,
password,
})
.then((response) => {
console.log(response.data);
})
.catch(error => {
if (error.response) {
console.log(error.response.data);
}
});
}
<Formik
initialValues={{ name: '', email: '', password: '' }}
onSubmit={handleSubmit}
validationSchema={validationSchema}
>
{ ({ handleChange, handleSubmit }) => (
<>
<View><Text>Show the error message here <Text/></View>
{/* -------------- Form -------------- */}
<View>
<TextInput
onChangeText={handleChange("name")}
placeholder = 'Name'
/>
...... other form here
</View>
{/* -------------- Button -------------- */}
<TouchableOpacity onPress={ handleSubmit } >
<TextBold style={styles.fontColor}>Submit</TextBold>
</TouchableOpacity>
</>
) }
</Formik>
reactjs
react-native
expo
formik
0 Answers
Your Answer