Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/exercise/06.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ function UsernameForm({onSubmitUsername}) {

// 🐨 make sure to associate the label to the input.
// to do so, set the value of 'htmlFor' prop of the label to the id of input
const [username, setUsername] = React.useState(null);

const handleSubmit = (event) => {
onSubmitUsername(username);

event.preventDefault();
};
const handleChange = (event) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could shorten if wanted :)

Suggested change
const handleChange = (event) => {
const handleChange = (event) => setUsername(event.target.value.toLowerCase());

const value = event.target.value.toLowerCase();
setUsername(value);
};

return (
<form>
<form onSubmit={handleSubmit}>
<div>
<label>Username:</label>
<input type="text" />
<label htmlFor="username">Username:</label>
<input type="text" id="username" onChange={handleChange} value={username} />
</div>
<button type="submit">Submit</button>
</form>
Expand Down