Load a React list with useEffect while handling endpoint changes, cleanup, stale responses, HTTP and schema errors, stable keys, and user-visible states.
Implement a React component that uses `useEffect` to load and display a list.
### Constraints & Assumptions
The reported task names useEffect and a list but does not provide an endpoint. For this practice version, receive an `endpoint` prop that returns a JSON array of `{id,label}` objects with unique string IDs. Display loading, empty, success, and error states. When the endpoint changes, an old response must not replace the new endpoint's state.
### Clarifying Questions
Who owns fetching and caching? What should happen while switching endpoints? Can the request be canceled? How does the component behave on unmount?
### What a Strong Answer Covers
A correct effect dependency, cleanup and stale-response protection, HTTP and data-shape error handling, and stable list keys.
### Follow-up Questions
Why should the effect callback itself not be async? What can development effect setup/cleanup cycles reveal? How would you add retries or share results among components?
Overview: Load a React list with useEffect while handling endpoint changes, cleanup, stale responses, HTTP and schema errors, stable keys, and user-visible states.
Implement a React component that uses useEffect to load and display a list.
Constraints & Assumptions
The reported task names useEffect and a list but does not provide an endpoint. For this practice version, receive an endpoint prop that returns a JSON array of {id,label} objects with unique string IDs. Display loading, empty, success, and error states. When the endpoint changes, an old response must not replace the new endpoint's state.
Clarifying Questions Guidance
Who owns fetching and caching? What should happen while switching endpoints? Can the request be canceled? How does the component behave on unmount?
What a Strong Answer Covers Guidance
A correct effect dependency, cleanup and stale-response protection, HTTP and data-shape error handling, and stable list keys.
Follow-up Questions Guidance
Why should the effect callback itself not be async? What can development effect setup/cleanup cycles reveal? How would you add retries or share results among components?