I am trying to display the alert message or the response message in <AppForm>
but nothing is being displayed.
alert('Patient Created, Patient ID :' + result.data.id);
I get the alert result from function ListingEditScreen
where there is an ID in result
result.data.id
I want to show the message in controller or even in a separate <Screen>
.
i have tried adding the result to <AppForm>
like below but it shows nothing.
<h1>{result.data.id}</h1>
<p>{result.data.gender}</p>
Can anyone please explain how do i display alert message/server response in <AppFrom>
function ListingEditScreen({ result = { data: '', id: '' } }) {
const handleSubmit = async (patients) => {
result = await patientApi.postPatients({ ...patients });
console.log(result)
if (!result.ok)
return alert('Could not post to Server');
alert('Patient Created, Patient ID :' + result.data.id);
}
return (
<Screen style={styles.container}>
<h1>{result.data.id}</h1>
<p>{result.data.gender}</p>
<AppForm
initialValues={{
"resourceType": '',
name: '',
gender: ''
}}
onSubmit={handleSubmit}
>
<FormField
maxLength={50}
name="resourceType"
placeholder='resourceType' />
<FormField
maxLength={40}
name='name[family]'
placeholder='last name'
/>
<FormField
maxLength={15}
name='gender'
placeholder='gender'
/>
<SubmitButton title='Post'/>
<h1>{result.data.id}</h1>
<p>{result.data.gender}</p>
</AppForm>
</Screen>
);
}
question from:
https://stackoverflow.com/questions/65904100/react-native-how-to-display-alert-message-in-appform-controller 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…