import React, { useState } from "react";
export default function EditProfile() {
const [profile, setProfile] = useState({});
const handleChange = ({ target }) => {
const { name, value } = target;
setProfile((prevProfile) => ({
...prevProfile,
[name]: value
}));
};
const handleSubmit = (event) => {
event.preventDefault();
alert(JSON.stringify(profile, '', 2));
};
return (
<form onSubmit={handleSubmit}>
<input
value={profile.firstName || ''}
onChange={handleChange}
name="firstName"
type="text"
placeholder="First Name"
/>
<input
value={profile.lastName || ''}
onChange={handleChange}
type="text"
name="lastName"
placeholder="Last Name"
/>
<input
value={profile.bday || ''}
onChange={handleChange}
type="date"
name="bday"
/>
<input
value={profile.password || ''}
onChange={handleChange}
type="password"
name="password"
placeholder="Password"
/>
<button type="submit">Submit</button>
</form>
);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter