Question presented to candidate: "Our contact picker uses react-window's fixed-size list over 100,000 contacts. Rebuild the component it gives us, with the same props, so we understand what it does: 48px rows, a 400px box, five rows of overscan, a scroll-to-row method we can call from outside, and arrow-key navigation through the contacts."
Requirements:
- A
FixedSizeListcomponent with react-window style props:height,itemCount,itemSize,itemData,overscanCount,onItemsRendered, and a row component passed as children that receivesindex,styleanddata. - An imperative
scrollToItem(index, align)exposed through a ref, with"auto","start","center"and"end"alignment. - Arrow Up/Down, Page Up/Down, Home and End move an active row and keep it in view; a "Jump to #" form scrolls a given row to the top.
- The active row is exposed to assistive technology, and the scrollbar reflects all 100,000 rows.
What a strong answer should cover:
- The fixed-size maths (index from
scrollOffset / itemSize) and why fixed heights make it O(1). - The row contract: the list owns positioning through
style, the row owns content, and shared values travel initemDataso a memoised row can skip renders. - Stable
styleobjects per index, otherwiseReact.memoon the row is useless. - Alignment rules for
scrollToItem, especially that"auto"scrolls only as far as needed, and updating the offset without waiting for the asynchronous scroll event. - Keyboard and ARIA: a focusable
role="listbox"witharia-activedescendantpointing only at a row that is actually mounted. - Awareness that react-window 2 renamed the API (
List,rowComponent,rowProps,listRef.scrollToRow).
Clarifying questions expected:
- "Which react-window major are we on? Version 2 changed the component and prop names."
- "Does selection need to survive scrolling the active row out of view?"
- "Is the list height fixed, or should it fill its parent?"
Code / implementation expected: Yes. A reusable list component plus a consumer that wires the ref, keyboard handling and jump form. The real library can be shown as a short usage snippet.