Skip to content

Instantly share code, notes, and snippets.

@Wanuja97
Created September 22, 2023 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wanuja97/ca6f83fdaefd2df9c0b322cb4fc3ea0d to your computer and use it in GitHub Desktop.
Save Wanuja97/ca6f83fdaefd2df9c0b322cb4fc3ea0d to your computer and use it in GitHub Desktop.
Client Side Rendering - Next.js
'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