Quiz - URL-state list views
You’re reviewing a teammate’s invoices list. They demo it: clicking a status filter visibly narrows the table, sorting flips the order, paging swaps the rows — every interaction works. But you notice the address bar never changes. What’s the verdict?
useEffect that writes the current filter/sort/page into the URL after each render so links still work.useEffect syncing state into the URL (the URL is the state — there’s no second copy to sync); the controls should write the URL directly via the setter.In the list view, a user changes a filter chip. Which navigation call belongs in the control, and why?
router.push('?status=overdue', { scroll: false }) — every state change is a distinct view the user should be able to step back to.router.replace('?status=overdue', { scroll: false }) — reconfiguring the current view should swap the history entry in place, so the back button leaves the list instead of rewinding chips one at a time.router.push('/invoices/overdue') — filter changes are genuine navigation to a new page.replace (with { scroll: false } so a long list doesn’t jump to the top); push is reserved for genuine navigation like clicking a row to open its detail page. If every chip pushed a history entry, a user who set five filters would hit back five times just to leave the screen.The sort parameter could be typed as parseAsString (accept any column name) or parseAsStringEnum([...]) (a closed list of columns). The course insists on the enum. Which problems does the enum prevent that a free string would allow? Select all that apply.
?sort=passwordHash reaching the query and ordering rows by a column that should never be exposed — the sort value is the column, which the driver can’t parameterize away..withDefault(...), enum or not.In the search box, you use both React’s useDeferredValue and nuqs’s limitUrlUpdates: debounce(300). A reviewer says one is redundant — pick one. Are they right?
useDeferredValue alone (or the debounce alone) covers it; keeping both is belt-and-suspenders.useDeferredValue is render priority on this device (adaptive, coalesces keystrokes), while debounce keeps partial input from writing the URL and hitting the server — a threshold meaningful outside the browser.useDeferredValue controls the URL write and debounce controls the input’s repaint, so removing either breaks a different half of the box.useDeferredValue is a priority marker that adapts to the device’s render budget and coalesces keystrokes for rendering; the debounce puts a hard floor on how often the URL is written and — because the write is shallow: false — how often the database is queried. One protects the render loop, the other protects the history stack and the server. (The third option inverts their jobs: the deferred value drives the URL write, the typed value drives the instant input repaint.)A search write needs shallow: false. What does dropping that option do?
value desyncs from the URL, so the box stops reflecting what the user typed.shallow: true — it updates the URL on the client only, which is right for client-read state but wrong for a server-rendered list. shallow: false is the load-bearing option that makes the committed write reach the server and re-run the query. (History spam is governed by the history option, which already defaults to 'replace'; the input/URL split is handled by typed-vs-committed state, not shallow.)Cursor pagination is the chapter’s default. When is reaching for offset (?page=N) instead the right call?
A coworker pastes you a cursor-paginated link. By the time you open it, two new invoices have been created above the encoded position. You see rows your coworker never saw, and they file “the pagination link is broken.” What’s the correct response?
Quiz complete
Score by topic