Skip to content

Instantly share code, notes, and snippets.

import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import { getSession, signOut } from 'next-auth/react';
import { Session } from '../api/auth/auth.types';
import { routes } from '../routes';
class AxiosProvider {
private axiosInstance: AxiosInstance;
constructor() {
this.axiosInstance = axios.create({
import { useRouter, useSearchParams } from 'next/navigation';
export function useRouterWithQuery() {
const router = useRouter();
const searchParams = useSearchParams();
const query = searchParams?.size ? `?${searchParams}` : '';
const replaceWithQuery = (url: string) => router.replace(`${url}${query}`);
const pushWithQuery = (url: string) => router.push(`${url}${query}`);
return { router, replaceWithQuery, pushWithQuery };
@justgeek
justgeek / calender.component.jsx
Created January 3, 2025 15:29
A simple react calendar component
import React, { useEffect, useState } from 'react';
import './Calendar.scss';
import { CalendarMolecule } from 'molecules/Calendar';
import { WeekBarMolecule } from 'molecules/WeekBar';
import { VirtualScroller } from 'elements/VirtualScroller';
import { instanceOf, func, bool } from 'prop-types';
import classNames from 'classnames';
const TOTAL_MONTHS = 200 * 12; // 100 years ahead + 100 years behind
const FRAME_HEIGHT = 270; // next month should be visible to make user aware of scrolling possibility
import {
addMonths,
addYears,
eachDayOfInterval,
eachMonthOfInterval,
eachWeekOfInterval,
endOfMonth,
endOfWeek,
isAfter,
isBefore,
@justgeek
justgeek / virtual-scroller.js
Created January 3, 2025 15:16
a simple react script to create virtual scroller with performance optimization
/* eslint-disable react/prop-types */
// inspired from this great article https://blog.logrocket.com/virtual-scrolling-core-principles-and-basic-implementation-in-react/
import React, { useRef, useEffect, useState } from 'react';
import { shape, func, string, number } from 'prop-types';
import './VirtualScroller.scss';
export function VirtualScroller(props) {
const { settings, row, generateItems } = props;
const viewportElement = useRef();
const [state, setState] = useState({ data: [] });
@justgeek
justgeek / detect-edge.hook.js
Last active January 3, 2025 15:22
React hook for viewport edge detection
import { useEffect, useState } from 'react';
export const useViewportEdgeActions = ({ element, parent, reCalculate }) => {
const [edgeState, setEdgeState] = useState({
isCloseToRightEdge: false,
isCloseToLeft: false,
isCloseToTop: false,
isCloseToBottom: false,
});