The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add fadeInDuration to ClientOnly
Steven Teyc1f3d4c17e0b
diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex 4d687520e6..228979dae3 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -1,7 +1,7 @@{"name": "@dub/ui","description": "UI components for Dub.co",- "version": "0.1.2",+ "version": "0.1.7","sideEffects": false,"main": "./dist/index.js","module": "./dist/index.mjs",diff --git a/packages/ui/src/client-only.tsx b/packages/ui/src/client-only.tsxindex c91592dfd6..68e3f8fa5b 100644--- a/packages/ui/src/client-only.tsx+++ b/packages/ui/src/client-only.tsx@@ -1,11 +1,14 @@+import { AnimatePresence, motion } from "framer-motion";import { ReactNode, useEffect, useState } from "react";export const ClientOnly = ({children,fallback,+ fadeInDuration = 0.5,}: {children: ReactNode;fallback?: ReactNode;+ fadeInDuration?: number;}) => {const [clientReady, setClientReady] = useState<boolean>(false);@@ -13,5 +16,25 @@ export const ClientOnly = ({setClientReady(true);}, []);- return clientReady ? children : fallback || null;+ const Comp = fadeInDuration ? motion.div : "div";++ return (+ <AnimatePresence>+ {clientReady ? (+ <Comp+ {...(fadeInDuration+ ? {+ initial: { opacity: 0 },+ animate: { opacity: 1 },+ transition: { duration: fadeInDuration },+ }+ : {})}+ >+ {children}+ </Comp>+ ) : (+ fallback || null+ )}+ </AnimatePresence>+ );};