I've managed to hard code the email and password into the fetch request but I want to get the values from the form.
Also when i get the response how to I check that the response code is 200 or 400?
import React, { useState } from 'react';
import loading from '../images/loading.svg';
const ButtonSpinner: React.FC = () => {
const [state, setState] = useState({loading: false});
async function submitForm() {
setState({ ...state, loading: true});
const response = await fetch(`http://127.0.0.01/user/register`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({email: 'test@gmail.com', password: 'test'})
});
const content = await response.json();
setState({ ...state, loading: false});
}
return (
<span>
<label>Email</label>
<input type="input" id='email'></input>
</span>
<span>
<label>Password</label>
<input type="password" id="password"></input>
</span>
<button className="btn-join" onClick={submitForm}>
{!state.loading ? 'Join Now!' : <img src={loading} alt="loading" />}
</button>
);
}
export {ButtonSpinner};