I have a basic form in a react 16 app. Upon successful submission of the form I am switching a variable from false
to true
and I then want to display a different div once the boolean is switched.
Here is my variable declaration and form submit function:
var formSubmitted = false;
const formObj = {};
const requestInfo = (formObj) => {
formObj.modelNumber = product.modelNumber
submitForm(formObj)
.then(value => {
formSubmitted = true;
console.log(formSubmitted);
}, reason => {
// rejection
});
};
Here is the conditional HTML:
<div>Always showing</div>
{ !formSubmitted &&
<div>Form has not been submitted</div>
}
{ formSubmitted &&
<div>Form submitted successfully</div>
}
The form is submitting successfully and the console.log is showing the variable formSubmitted
was successfully switched from false
to true
, however the HTML is not changing. I'm new to react 16 and I'm not sure how to update the component.
Thank you.