Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
82 views
in Technique[技术] by (71.8m points)

javascript - React Native how to display alert message in <AppForm> Controller

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...