I am learning how to use React and started using classes and decided to swap over to using Hooks. I believe that I have everything mapped out correctly, however I am very uncertain of how to structure my axios.post with useEffect to handle multiple user inputs.
import React, { useState, useEffect } from 'react'
import axios from 'axios'
const Signup = () => {
const [customerSignUp, setCustomerSignUp] = useState([
{ email: '', password: '', firstName: '', lastName: ''}
]);
const handleChange = (event) => {
setCustomerSignUp(event.target.value)
}
const handleSubmit = (e) => {
e.preventDefault()
console.log(e)
}
useEffect(() => {
axios.post('/api/Customer/SignUp', {
})
.then(function (response) {
console.log(response)
})
.catch(function (error) {
console.log(error)
})
}, [])
I included just the lastName to show how I am using the handleChange event handler to change the state of the customer.
return (
<div className="container">
<form className='white' onSubmit={handleSubmit}>
<h5 className="grey-text.text-darken-3">Sign Up With Email</h5>
<div className="input-field">
<label htmlFor="lastName">Last Name</label>
<input type="text" name="lastName" value={customerSignUp.lastName} onChange={handleChange} required />
</div>
<div className="input-field">
<button className="btn blue darken-3" type="submit">Sign Up</button>
</div>
</form>
</div>
);
}
export default Signup