Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

BytesForm.js

49 lines1.3 KB

1import React from 'react'
2import useBytesSubmit from './useBytesSubmit'
3​
4export default function BytesForm() {
5 const { state, handleSubmit, error } = useBytesSubmit()
6 if (state === 'submitted') {
7 return (
8 <p>Success! Please, check your email to confirm your subscription.</p>
9 )
10 }
11 return (
12 <form onSubmit={handleSubmit}>
13 <div data-element="fields" className="grid relative">
14 <figure
15 className="absolute right-0"
16 style={{ bottom: '72px', right: '-10px' }}
17 >
18 <img
19 height={40}
20 width={40}
21 src="/images/bytes-logo.png"
22 alt="Bytes"
23 />
24 </figure>
25 <input
26 className="border rounded p-2 mb-2 w-full"
27 name="email_address"
28 placeholder="Your email address"
29 type="email"
30 required=""
31 />
32 <button
33 type="submit"
34 className="mb-4 border rounded bg-coral border-none text-white p-2"
35 >
36 {state !== 'loading' ? (
37 <span>Subscribe</span>
38 ) : (
39 <span>Loading...</span>
40 )}
41 </button>
42 </div>
43 <p className="text-gray-400 text-xs">
44 No spam. Unsubscribe at <em>any</em> time.
45 </p>
46 {error && <p className="text-red-600">{error}</p>}
47 </form>
48 )