Created
October 19, 2019 09:59
-
-
Save alexandermckay/4747d0a9ca275761034926e6be1cba0d to your computer and use it in GitHub Desktop.
react-app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Axios from 'axios'; | |
import React, { useState } from 'react'; | |
const sendEmailURL = '<YOUR_FUNCTION_URL>'; | |
function App() { | |
const [state, setState] = useState({ | |
message: '', | |
name: '', | |
subject: '', | |
}); | |
const { message, name, subject } = state; | |
const handleState = ({ target: { id, value } }) => | |
setState({ ...state, [id]: value }); | |
const sendEmail = (e) => { | |
e.preventDefault(); | |
Axios.get(sendEmailURL, { | |
params: { | |
message, | |
name, | |
subject, | |
}, | |
}); | |
}; | |
return ( | |
<form | |
onSubmit={sendEmail} | |
style={{ | |
alignItems: 'center', | |
display: 'flex', | |
flexDirection: 'column', | |
}} | |
> | |
<label htmlFor={'name'}>Name</label> | |
<input id={'name'} onChange={handleState} value={name} /> | |
<label htmlFor={'message'}>Message</label> | |
<input | |
id={'message'} | |
onChange={handleState} | |
value={message} | |
/> | |
<label htmlFor={'subject'}>Subject</label> | |
<input | |
id={'subject'} | |
onChange={handleState} | |
value={subject} | |
/> | |
<input type={'submit'} value={'Send Email'} /> | |
</form> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment