From d74ebc2df76efb08212ee2f4bd037ae083fd9ab6 Mon Sep 17 00:00:00 2001 From: tomiir Date: Tue, 2 Jul 2024 17:31:05 -0600 Subject: [PATCH] fix: add default value and check before setting href --- apps/laboratory/src/components/RandomLink.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/laboratory/src/components/RandomLink.tsx b/apps/laboratory/src/components/RandomLink.tsx index 37dbcae0cb..d95247a047 100644 --- a/apps/laboratory/src/components/RandomLink.tsx +++ b/apps/laboratory/src/components/RandomLink.tsx @@ -3,11 +3,19 @@ import Link from 'next/link' import { useState, useEffect } from 'react' -export function RandomLink({ hrefs, children }: { hrefs: string[]; children: React.ReactNode }) { +export function RandomLink({ + hrefs = [], + children +}: { + hrefs: string[] + children: React.ReactNode +}) { const [href, setHref] = useState() useEffect(() => { const newHref = hrefs[Math.floor(Math.random() * hrefs.length)] - setHref(newHref) + if (newHref) { + setHref(newHref) + } }, [hrefs]) return href ? {children} : <>