I have a component here that gets an ID number and checks if that ID number exists in the database. If it exists, it should render a component and show an error message if not. Struggling with how I should write it, any help is appreciated.
function PatientIDInput({component}) {
const [patientID, setPatientID] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [showComponent, setShowComponent] = useState(false);
const [patientInformation, setPatientInformation] = useState('');
const handleChange = (e) => {
// some input change handling
}
const handleSubmit = (e) => {
e.preventDefault();
Physician.fetchPatientData(patientID)
.then(res => {
if (res.status === 200) {
// show component if patient exists
}
})
.catch(error => {
if (error.response.status) {
// set error if not
}
})
}
return (
<>
<form onSubmit={handleSubmit}>
// some UI code for user's input
</form>
{ showComponent
? {Component patientInformation={patientInformation}} /> // this is where I'm
struggling with the syntax. How should I write the logic? I want to pass
some props to the component too.
: null}
</>
);
}
export default PatientIDInput;