Complete the code to import the hook used for reading URL search parameters in Remix.
import { [1] } from "@remix-run/react";
The useSearchParams hook lets you read and update the URL's query string in Remix.
Complete the code to get the current search query from the URL parameters.
const [searchParams] = [1](); const query = searchParams.get("q") || "";
useSearchParams returns an array where the first element is the current URL search parameters object.
Fix the error in the loader function to read the search query from the request URL.
export async function loader({ request }) {
const url = new URL(request.[1]);
const q = url.searchParams.get("q") || "";
return { q };
}The request.url property contains the full URL string, which you can pass to the URL constructor to access search parameters.
Fill both blanks to create a form that submits the search query using GET method and updates the URL.
<form method=[1] action="/search"> <input type="search" name=[2] aria-label="Search query" /> <button type="submit">Search</button> </form>
Using method="get" makes the form submit the query in the URL. The input's name must match the query parameter key, here "q".
Fill all three blanks to display the search query from loader data and update the input value accordingly.
export default function SearchPage() {
const data = useLoaderData();
return (
<main>
<form method="get">
<input
type="search"
name="q"
aria-label="Search query"
defaultValue=[1]
/>
<button type="submit">Search</button>
</form>
<p>Showing results for: <strong>[2]</strong></p>
<ul>
{data.results?.map((item) => (
<li key={item.id}>{item.[3]</li>
))}
</ul>
</main>
);
}The input's defaultValue and the displayed query text both come from data.q. The list shows each item's title property.