KatInterview

Frontend State Management and Form Handling

Data Structure DesignModel answer
MediumModel answerData Structure Designfrontendstate-managementform-validation

Last updated

Build a web interface that manages list state, handles form submission with proper error recovery, integrates with APIs, and maintains data consistency.

You're building a web application that demonstrates fundamental frontend engineering skills. Your implementation must handle state correctly, integrate with backend services, and provide a good user experience.

Requirements:

  1. List rendering: Display items from an array in memory. Use BEM naming convention with double underscores for CSS classes (e.g., component__element). Single underscores should not be used.

  2. Form handling: Create a form that adds new items to the list. When submission fails (like a 400 error), preserve the user's input and display an error message. When submission succeeds, add the item to the list and clear the form.

  3. API integration: Load items from a backend endpoint and display them. Handle three states: loading, success, and error. When merging server data with locally-created items, prevent duplicates.

  4. Quality requirements: Implement proper accessibility (associate labels with inputs, use correct button types), ensure operations are idempotent, and make rendering predictable.

Discussion points:

Explain your approach to event handling, state management, and error handling. Describe how you would organize files and components, and how you would test these behaviors.

Hints

Hint 1

Consider what happens when API responses arrive out of order or a user clicks submit multiple times

Hint 2

Think about who owns the form input values—the browser or your rendering logic

Hint 3

Use unique identifiers to reconcile local and server data without creating duplicates