Skip to content

Commit

Permalink
Refactor Tabs component to use useRouter hook
Browse files Browse the repository at this point in the history
  • Loading branch information
NiallJoeMaher committed Jan 6, 2024
1 parent 0354a74 commit 1a52b3e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions components/Tabs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redirect } from "next/navigation";
import { useRouter } from "next/navigation";
import Link from "next/link";

function classNames(...classes: string[]) {
Expand All @@ -18,6 +18,8 @@ type Props = {

export function Tabs(props: Props) {
const { tabs } = props;
const router = useRouter();

return (
<div className="max-w-5xl">
<div className="sm:hidden">
Expand All @@ -30,11 +32,13 @@ export function Tabs(props: Props) {
className="block w-full rounded-md border-neutral-300 focus:border-neutral-500 focus:ring-neutral-500"
defaultValue={tabs.find((tab) => tab.current)?.name || tabs[0].name}
onChange={(e) => {
redirect(`?tab=${e.target.value}`);
router.push(e.target.value);
}}
>
{tabs.map((tab) => (
<option key={tab.name}>{tab.name}</option>
<option value={tab.href} key={tab.name}>
{tab.name}
</option>
))}
</select>
</div>
Expand Down

0 comments on commit 1a52b3e

Please sign in to comment.