Created
September 22, 2023 13:55
-
-
Save Wanuja97/ca6f83fdaefd2df9c0b322cb4fc3ea0d to your computer and use it in GitHub Desktop.
Client Side Rendering - Next.js
This file contains hidden or 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'; // Disable server-side rendering with this statement in the component file | |
import React from 'react' | |
import TimeCard from './TimeCard' | |
import axios from 'axios'; | |
import { useState, useEffect } from 'react' | |
export default function CSR() { | |
const [dateTime, setDateTime] = useState(''); | |
useEffect(() => { | |
axios | |
.get('https://worldtimeapi.org/api/ip') // Make a request for take the date and time from the API | |
.then((res) => { | |
setDateTime(res.data.datetime); // Set the date and time | |
}) | |
.catch((error) => console.error(error)); // Catch the error | |
}, [dateTime]); | |
return ( | |
<div> | |
<TimeCard title="Client Side Rendering" timestamp={dateTime} description="This timestamp is generating inside the client." /> | |
</div> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment