scrimba
Meta scrims
React Advanced
Lab Solution: Create a registration form
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Lab Solution: Create a registration form
AboutCommentsNotes
Lab Solution: Create a registration form
Expand for more info
src
App.js
run
preview
console
import { useState } from "react";
import { validateEmail } from "./utils";

const PasswordErrorMessage = () => {
return (
<p className="FieldError">Password should have at least 8 characters</p>
);
};

function App() {
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState({
value: "",
isTouched: false,
});
const [role, setRole] = useState("role");

const getIsFormValid = () => {
// Implement this function

return false;
};

const clearForm = () => {
// Implement this function
};

const handleSubmit = () => {
alert("Account created!");
clearForm();
};

return (
<div className="App">
<form onSubmit={handleSubmit}>
<fieldset>
<h2>Sign Up</h2>
<div className="Field">
<label>
First name <sup>*</sup>
</label>
<input placeholder="First name" />
</div>
<div className="Field">
<label>Last name</label>
<input placeholder="Last name" />
</div>
<div className="Field">
<label>
Email address <sup>*</sup>
</label>
<input placeholder="Email address" />
</div>
<div className="Field">
<label>
Password <sup>*</sup>
</label>
<input placeholder="Password" />
</div>
<div className="Field">
<label>
Role <sup>*</sup>
</label>
<select>
<option value="role">Role</option>
<option value="individual">Individual</option>
<option value="business">Business</option>
</select>
</div>
<button type="submit" disabled={!getIsFormValid()}>
Create account
</button>
</fieldset>
</form>
</div>
);
}

export default App;
Console
/public/index.html
-8:31