Download next.js/examples/cms-storyblok/components/date.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 439 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/cms-storyblok/components/date.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/examples/cms-storyblok/components/date.js
-
curl -L -o date.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/cms-storyblok/components/date.js
439 Bytes
| import { parseISO, format } from "date-fns"; | |
| import { useEffect, useState } from "react"; | |
| // dateString might be null for unpublished posts | |
| export default function DateComponent({ dateString }) { | |
| const [date, setDate] = useState(dateString ? parseISO(dateString) : null); | |
| useEffect(() => { | |
| if (!date) { | |
| setDate(new Date()); | |
| } | |
| }, [date]); | |
| return date && <time dateTime={date}>{format(date, "LLLL d, yyyy")}</time>; | |
| } | |