-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate-email.js
48 lines (42 loc) · 1.13 KB
/
validate-email.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { useState } from 'react';
import axios from 'axios';
const Page = () => {
const [userEmail, setUserEmail] = useState();
const [response, setResponse] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
const handleSubmit = async (event) => {
event.preventDefault();
setIsSubmitting(true);
try {
const response = await axios.post('/api/validate-email', {
email: userEmail
});
setResponse(response.data.message);
setIsSubmitting(false);
} catch (error) {
setResponse(error.response.data.message);
setIsSubmitting(false);
}
};
return (
<main>
<h1>
Validate email <br />
addresses server-side
</h1>
<form onSubmit={handleSubmit}>
<input
type="text"
placeholder="your@email.com"
value={userEmail}
onChange={(event) => setUserEmail(event.target.value)}
/>
<button type="submit" disabled={!userEmail || isSubmitting}>
Submit
</button>
</form>
<small>{response}</small>
</main>
);
};
export default Page;