You can use only one Function for all onChanges.(您只能对所有onChanges使用一个功能。)
Looks like this;(看起来像这样;)
<Form.Group>
<Form.Control
type="text"
name="Firstname"
placeholder="Firstname"
value={Student.Firstname}
onChange={handleChange}
/>
</Form.Group>
And this is your handleChange function;(这是您的handleChange函数;)
const handleChange = e => {
const {name, value} = e.target
setValues({...values, [name]: value})
}
This is your state;(这是你的状态;)
const [values, setValues] = useState({
Firstname: "",
Middlename: "",
Lastname: "",
DOB: "",
Gender: ""
})
I think this way is more effective with less code.(我认为这种方式用更少的代码更有效。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…