Skip to content

Instantly share code, notes, and snippets.

@MisterJimson
Created September 24, 2024 20:24
Show Gist options
  • Save MisterJimson/07df31040756701f8b034c08e6acabf1 to your computer and use it in GitHub Desktop.
Save MisterJimson/07df31040756701f8b034c08e6acabf1 to your computer and use it in GitHub Desktop.
local-date.tsx
'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