Skip to content

Instantly share code, notes, and snippets.

View EliasAfara's full-sized avatar
🌌
Embracing the Void

Elias Afara EliasAfara

🌌
Embracing the Void
View GitHub Profile
@EliasAfara
EliasAfara / ScrollToTop.js
Created June 25, 2023 01:21
React scroll to top using react router dom
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
const ScrollToTop = () => {
const location = useLocation();
console.log(location);
useEffect(() => {
try {
@EliasAfara
EliasAfara / getRepoStarsAndForks.js
Created June 25, 2023 01:22
Fetch Github Repository Stars and Forks
export async function getRepoStarsAndForks(owner, repo, token) {
const endpoint = `https://api.github.com/repos/${owner}/${repo}`;
const headers = {
Authorization: `Token ${token}`,
};
try {
const response = await fetch(endpoint, { headers });
const data = await response.json();
@EliasAfara
EliasAfara / formatDate.js
Created June 25, 2023 21:45
Format Date Function
const Min = 60 * 1000; // milliseconds in Minute
const Hour = Min * 60; // milliseconds in Hour
const Day = Hour * 24; // milliseconds in day
const Week = Day * 7; // milliseconds in week
const Month = Day * 30; // milliseconds in Month
//.toISOString()
export const formatDate = (date) => {
const currentDate = new Date();
const previousDate = new Date(date);