Created
September 24, 2024 20:24
-
-
Save MisterJimson/07df31040756701f8b034c08e6acabf1 to your computer and use it in GitHub Desktop.
local-date.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client'; | |
import { format as dateFnsFormat } from 'date-fns/format'; | |
import dynamic from 'next/dynamic'; | |
import { Skeleton } from '~/components/ui/skeleton'; | |
export const DisplayLocalDate = dynamic( | |
() => import('./DisplayLocalDate').then((res) => res.DisplayLocalDateClient), | |
{ ssr: false, loading: () => <Skeleton className="mx-1 h-4 w-20" /> } | |
); | |
export function DisplayLocalDateClient({ | |
date, | |
format = 'MMM d, yyyy' | |
}: { | |
date: string; | |
format?: string; | |
}) { | |
const dateObj = new Date(date); | |
return dateFnsFormat(dateObj, format); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment