Question presented to candidate: "We have a search box on every page that sends the user to a results page with the query in the URL. Someone suggested using the Form component from next/form instead of a plain form. What does it do differently, and when would you not use it?"
What a strong answer should cover:
<Form>fromnext/formextends the HTML<form>; it shipped with Next.js 15.- With a string
actionit behaves like a GET form: input values become search params (/search?query=abc), but Next.js performs a client-side navigation instead of a full reload, keeping layouts and client state. - It prefetches the target route's shared UI (layouts,
loading.js) when the form is visible, so loading UI appears instantly on submit; propsreplace,scroll,prefetch. - Progressive enhancement: without JavaScript it is a normal GET form, so search still works.
- With a function
action(a Server Action) it is just a React form for mutations: no prefetch,replaceandscrollignored. - Not for:
method="post"to an external URL,target,encType, or file inputs with a string action; use a plain<form>.
Clarifying questions expected:
- "Is the form navigating to a URL (search, filter) or changing data (create, update)?" β string action versus Server Action.
- "Should each search create a history entry?" β the
replaceprop.
Code / implementation expected: Yes β a search form with a string action and a results page reading searchParams.