Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Routing and Application Architecture
Stage 5: Specialization (pick ONE)

Part 05 / Topic 7 of 7

Putting it together: a sign-up form

examples/07_signup_form.jsx combines every section above into one form: a single object (details) holding name, email, password, and city in object-shaped state (section 2), a controlled <select> and checkbox alongside the text fields (section 3), a submit button disabled until the required text fields are filled (section 5), validation on submit with inline errors (section 4), preventDefault first (section 1), and one field - a referral code - left deliberately uncontrolled and read with a ref (section 6), because nothing else on screen needs to react to it while the user is still typing:

// examples/07_signup_form.jsx (trimmed)
function handleSubmit(event) {
  event.preventDefault();
  const nextErrors = validate(details);
  setErrors(nextErrors);
  if (Object.keys(nextErrors).length > 0) {
    setSuccessMessage("");
    return;
  }
  const referralCode = referralInputRef.current.value.trim();
  setSuccessMessage(
    referralCode
      ? `Welcome to Swiggy, ${details.name}! Referral code ${referralCode} applied.`
      : `Welcome to Swiggy, ${details.name}!`,
  );
}

examples/07_signup_form.test.jsx really drives this end to end: the submit button stays disabled until name, email, and password all have something typed into them; submitting with the terms checkbox left unchecked really shows "You must agree to the terms to sign up." and nothing else proceeds; filling in every required field, choosing "Pune" from the city dropdown, typing a referral code, and checking the terms box really shows "Welcome to Swiggy, Divya! Referral code ASHA50 applied."; the exact same form submitted with the referral field left blank really shows the shorter "Welcome to Swiggy, Kiran!" instead, because referralCode is an empty string and the ternary falls to its second branch. Nothing in this file is a new idea - every piece is a section above, wired together the same way the Stage 1 project (Menu Browser) will wire its own list, filter, and cart pieces together next.

Done here? The practice set for Part 5 — including the solutions — is on the part page.

Search the guide