Skip to content

Commit

Permalink
protip: add search prefetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanflorence committed Jan 11, 2022
1 parent a01762a commit 19c3993
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/components/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment, lazy, Suspense } from "react";
import { Form, Link } from "remix";
import { Fragment, lazy, Suspense, useState } from "react";
import { Form, Link, PrefetchPageLinks } from "remix";
import type { To } from "react-router-dom";
import { Popover, Transition } from "@headlessui/react";

Expand Down Expand Up @@ -42,6 +42,8 @@ export function Navbar({
| "Wishlist"
>;
}) {
let [prefetchQuery, setPrefetchSeachQuery] = useState("");

return (
<nav className="p-4 lg:px-6 border-b border-zinc-700">
<div className="flex">
Expand Down Expand Up @@ -100,8 +102,12 @@ export function Navbar({
name="q"
className=" p-2 bg-zinc-900 border border-zinc-700 w-full"
placeholder={translations?.["Search for products..."]}
onChange={(e) => setPrefetchSeachQuery(e.target.value)}
/>
</Form>
{prefetchQuery && (
<PrefetchPageLinks page={`/${lang}/search?q=${prefetchQuery}`} />
)}
</div>
<div className="flex items-center">
<Link
Expand Down

0 comments on commit 19c3993

Please sign in to comment.