Вы также должны указать атрибут значения в выбранном входе.
import React, { useState } from 'react';
import axios from 'axios';
const Dashboard = () => {
const [formState, setFormState] = useState({ size: '' });
const [post, setPost] = useState({});
const inputChange = (e) => {
setFormState({
size: e.target.value,
});
};
const onFormSubmit = (e) => {
e.preventDefault();
axios
.post('https://reqres.in/api/users', formState)
.then((res) => {
setPost(res.data);
setFormState({ size: '' });
})
.catch((err) => console.log(err.response));
};
console.log(post);
return (
<form onSubmit={onFormSubmit}>
<label htmlFor="size">
What size pizza would you like?
<br />
<select value={formState.size} name="size" id="sizeinput" onChange={inputChange}>
<option value="" disabled selected>Select</option>
<option value="Sm">Sm</option>
<option value="Lg">Lg</option>
<option value="XL">XL</option>
</select>
</label>
<button type="submit">Submit</button>
</form>
);
};
export default Dashboard;
именно здесь вы допустили ошибку
<select name = 'size' id = 'sizeinput' onChange = {inputChange}>
To
<select value={formState.size} name="size" id="sizeinput" onChange={inputChange}>