Skip to content

Instantly share code, notes, and snippets.

View Bonny-kato's full-sized avatar

Black Bonny-kato

View GitHub Profile
@Bonny-kato
Bonny-kato / HeadlessDatePicker Component with Month Navigation.md
Last active January 11, 2024 19:31
The code snippet defines a HeadlessDatePicker component that displays a calendar. It uses the dayjs library to get the current month and year, and generates an array representing the days of the month. The component allows the user to navigate to the previous or

HeadlessDatePicker Component with Month Navigation

Preview:
import * as dayjs from "dayjs";
import { Dayjs } from "dayjs";
import { useEffect, useState } from "react";

export const getMonth = (month = dayjs().month()) => {
    const year = dayjs().year();
    const firstDayOfMonth = dayjs(new Date(year, month, 1)).day();
@Bonny-kato
Bonny-kato / React Hook for Tracking User Inactivity.md
Last active September 1, 2023 04:25
React hook called `useIdleTimer` that tracks user activity and determines if the user is currently inactive. It takes in several configuration options as arguments and returns an object containing a boolean value indicating whether the user is currently inactive.

React Hook for Tracking User Inactivity

Preview:
import {
    getValueFromLocalStorage,
    localStorageKeys,
    removeValuesFromLocalStorage,
    saveValueToLocalStorage,
} from "@/utils/local-storage";
import { TFunction } from "@/types";
@Bonny-kato
Bonny-kato / Generate Query Parameters from Object.md
Created August 26, 2023 17:49
This code snippet generates a query string from an object of query parameters by iterating over the object, appending each key-value pair to a URLSearchParams object, and returning the resulting query string.

Generate Query Parameters from Object

Preview:
export const generateQueryParams = (params: QueryParams): string => {
    const queryParams = new URLSearchParams();

    for (const [key, value] of Object.entries(params)) {
        if (value) {
            queryParams.append(key, value.toString());
 }