Skip to content

Instantly share code, notes, and snippets.

@sametcn99
Created January 4, 2024 00:22
Show Gist options
  • Select an option

  • Save sametcn99/dacba6034067d275cfaa74738d078d8d to your computer and use it in GitHub Desktop.

Select an option

Save sametcn99/dacba6034067d275cfaa74738d078d8d to your computer and use it in GitHub Desktop.
This code appears to be a React component designed for redirection in a Next.js application. Let's break down the main components:
"use client";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import Loading from "@/app/loading";
type RedirectProps = {
searchParams: { url: string };
};
export default function Redirect({ searchParams }: RedirectProps) {
const router = useRouter();
useEffect(() => {
const redirectTimeout = setTimeout(() => {
router.push(searchParams.url);
}, 1000);
return () => clearTimeout(redirectTimeout);
}, [router, searchParams.url]);
return (
<section className="flex h-screen w-full flex-col items-center justify-center gap-4 text-2xl font-bold">
<h1>Redirecting...</h1>
</section>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment