cara mengedit beberapa input bereaksi
import React, { useState } from "react";
const initialContact = { firstName: "", lastName: "", phone: "" };
export default function App() {
const [contact, setContact] = useState(initialContact);
const handleChangeFor = (propertyName) => (event) => {
setContact((contact) => ({
...contact,
[propertyName]: event.target.value
}));
};
return (
<div>
<input
type="text"
onChange={handleChangeFor("firstName")}
value={contact.firstName}
/>
<input
type="text"
onChange={handleChangeFor("lastName")}
value={contact.lastName}
/>
<input
type="text"
onChange={handleChangeFor("phone")}
value={contact.phone}
/>
</div>
);
}
Energetic Elk