Debug a React Contact List: Form Validation, Callbacks, State and Props

Quick Overview

A front-end debugging task on a small React contact list built from App, AddPerson and ListPeople components. It tests form submission, required-field and 10-digit phone validation, passing callbacks from parent to child, immutable state updates and props, while keeping the existing test attributes intact.

Debug a React Contact List: Form Validation, Callbacks, State and Props

Company: BNY Mellon

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Online Assessment

In an online assessment you receive a small React app for a contact list built from three components: `App`, `AddPerson` and `ListPeople`. Adding a contact and seeing it appear in the list right away does not work. Fix the app so that it meets these requirements: - The form has three inputs: name (`type="text"`), phone (`type="number"`) and email (`type="email"`). - Name, phone and email are all required, and the phone number must be exactly 10 digits. - Submitting a valid form adds the contact, and the list shows it immediately. - Every existing `data-testid` and other attribute stays exactly as given, because the tests find elements by them. The report names the areas to inspect (form submission, the callback the parent passes to the child and the arguments it is called with, state updates, and the props passed to the list) but not the exact bugs. Explain the fault you would look for in each area, and write corrected versions of the three components. ```hint Follow one contact Trace a single valid submission from the submit event, through the callback App gives AddPerson, into the state App owns, and out through the props ListPeople renders. Check every hand-off. ``` ```hint Why the list may not move Ask what React compares to decide whether a state change needs a re-render, and what happens when an array is changed in place. ``` ### Constraints and Clarifications - Existing `data-testid` values and other attributes must be preserved; fixing the logic must not change what the tests select. - The phone input has type `number`, but the value it hands to an `onChange` handler is a string. ### Clarifying Questions - When a field is invalid, should the form show an error message, disable the submit button, or simply not add the contact? - Should the inputs be cleared after a successful add? - Can a 10-digit phone number start with 0, and must spaces, dashes or a country code be rejected? - Are duplicate contacts, such as the same phone number twice, allowed? - Is the app written with function components and hooks, or with class components? ### What a Strong Answer Covers - Submit handling that prevents the page reload and validates before adding - Validation of all three fields, including an exact 10-digit check that works on the string a number input produces - A callback passed from App as a function and invoked with the new contact, never called during render - Immutable state updates so the list re-renders immediately, with stable keys for list items - Matching prop names and values between App and its children, with all original test attributes preserved ### Follow-up Questions - A number input accepts characters such as `e`, `+` and `-`. How does your validation treat them? - How would you write a React Testing Library test that adds a contact and checks the list, and one that checks an invalid phone is rejected? - If the contacts had to survive a page reload, where would you keep them and how would you load them? - How would you show which field is invalid without breaking tests that select the existing elements?

Overview: A front-end debugging task on a small React contact list built from App, AddPerson and ListPeople components. It tests form submission, required-field and 10-digit phone validation, passing callbacks from parent to child, immutable state updates and props, while keeping the existing test attributes intact.

Read the full BNY Mellon Software Engineer interview experience this question came from

BNY Mellon logo
BNY Mellon
Oct 29, 2026
easySoftware EngineerOnline AssessmentSoftware Engineering Fundamentals
0
0

In an online assessment you receive a small React app for a contact list built from three components: App, AddPerson and ListPeople. Adding a contact and seeing it appear in the list right away does not work. Fix the app so that it meets these requirements:

  • The form has three inputs: name ( type="text" ), phone ( type="number" ) and email ( type="email" ).
  • Name, phone and email are all required, and the phone number must be exactly 10 digits.
  • Submitting a valid form adds the contact, and the list shows it immediately.
  • Every existing data-testid and other attribute stays exactly as given, because the tests find elements by them.

The report names the areas to inspect (form submission, the callback the parent passes to the child and the arguments it is called with, state updates, and the props passed to the list) but not the exact bugs. Explain the fault you would look for in each area, and write corrected versions of the three components.

Constraints and Clarifications

  • Existing data-testid values and other attributes must be preserved; fixing the logic must not change what the tests select.
  • The phone input has type number , but the value it hands to an onChange handler is a string.

Clarifying Questions Guidance

  • When a field is invalid, should the form show an error message, disable the submit button, or simply not add the contact?
  • Should the inputs be cleared after a successful add?
  • Can a 10-digit phone number start with 0, and must spaces, dashes or a country code be rejected?
  • Are duplicate contacts, such as the same phone number twice, allowed?
  • Is the app written with function components and hooks, or with class components?

What a Strong Answer Covers Guidance

  • Submit handling that prevents the page reload and validates before adding
  • Validation of all three fields, including an exact 10-digit check that works on the string a number input produces
  • A callback passed from App as a function and invoked with the new contact, never called during render
  • Immutable state updates so the list re-renders immediately, with stable keys for list items
  • Matching prop names and values between App and its children, with all original test attributes preserved

Follow-up Questions Guidance

  • A number input accepts characters such as e , + and - . How does your validation treat them?
  • How would you write a React Testing Library test that adds a contact and checks the list, and one that checks an invalid phone is rejected?
  • If the contacts had to survive a page reload, where would you keep them and how would you load them?
  • How would you show which field is invalid without breaking tests that select the existing elements?