React Native - 如何在应用程序屏幕上显示错误身份验证消息
我有一个注册屏幕,在其中,当我填写输入表格并提交输入表格时,一条错误消息“已经收集了电子邮件”,我想要在<<<<<<<<message>代码> CMD
在我的注册屏幕上显示。
regumtration.js屏幕
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论