I have this React form which I want to submit:
import React, {useState} from 'react';
const FooterOne = ({ footerLight }) => {
const handleFormSubmit = async (formValues) => {
const { email } = formValues;
const [response, setResponse] = useState("");
const body = {
email,
};
try {
const result = await fetch(
`https://.....lambda-url.us-east-1.on.aws/`,
{
method: "POST",
body: JSON.stringify(body),
}
);
const response = await result.text();
setResponse(response);
} catch (error) {
// Print error
}
};
return (
<>
<form className='newsletter-form position-relative d-block d-lg-flex d-md-flex' onSubmit={handleFormSubmit} >
<input
type='text'
className='input-newsletter form-control me-2'
placeholder='Enter your email'
name='email'
required=''
autoComplete='off'
value={this.state.value} onChange={this.handleChange}
/>
<input
type='submit'
value='Subscribe'
data-wait='Please wait...'
className='btn btn-primary mt-3 mt-lg-0 mt-md-0'
/>
</form>
</>
);
};
export default FooterOne;
How I can submit the form with minimum html code change? Also how I can submit the form using async POST call? I don’t need to wait for BE response.