Skip to content

Instantly share code, notes, and snippets.

View livemehere's full-sized avatar

livemehere livemehere

View GitHub Profile
@livemehere
livemehere / arr.ts
Created April 4, 2024 04:28
Be careful when initialize array with object
const _grid: T[][] = Array(cols).fill([]); // X (Each index value has same memory address)
const _grid: T[][] = Array.from({ length: cols }, () => []); // OK
const _grid: T[][] = Array(cols).fill(undefined).map(() => []); // OK
p {
display: -webkit-box;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
@livemehere
livemehere / useScrollWatcher.ts
Created March 27, 2024 05:54
Trigger on scroll or touch move
import { useEffect } from 'react';
const useScrollWatcher = () => {
useEffect(() => {
let timer: number;
const handler = (e: Event) => {
timer && clearTimeout(timer);
document.body.classList.add('scrollShow');
timer = window.setTimeout(() => {
document.body.classList.remove('scrollShow');
@livemehere
livemehere / useDetectTextLine.ts
Created March 27, 2024 05:47
hook :: detect text line count
import { RefObject, useEffect, useState } from 'react';
const useDetectTextLine = (target: RefObject<HTMLElement>) => {
const [line, setLine] = useState<number>();
useEffect(() => {
const el = target.current;
if (!el) return;
const observer = new ResizeObserver((entries) => {
entries.forEach((entry) => {
@livemehere
livemehere / layout.scss
Created March 25, 2024 06:17
React full page layout tips
html,
body,
#root {
width: 100%;
height: 100%;
}
* {
&::-webkit-scrollbar {
width: 12px;
@livemehere
livemehere / index.scss
Created March 25, 2024 06:12
Customize scroll bar
* {
&::-webkit-scrollbar {
width: 12px;
background:red;
}
&::-webkit-scrollbar-thumb {
background:blue;
border-radius: 18px;
border: 2px solid transparent;
@livemehere
livemehere / persistStore.ts
Created March 24, 2024 08:44
zustand persist boiler template
import { create } from "zustand";
import { createJSONStorage, devtools, persist } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";
type State = {
lastAccessTime: number;
};
type Actions = {
setLastAccessTime: (timestamp: number) => void;
@livemehere
livemehere / globalStore.ts
Last active March 24, 2024 08:44
zustand boiler template
import { create } from "zustand";
import { devtools } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";
type State = {
isDarkMode: boolean;
};
type Actions = {
toggleDarkMode: () => void;
@livemehere
livemehere / Get Browser scrollbar width.md
Last active March 24, 2024 08:43
Get Browser scrollbar width
  const getScrollbarWidth = () => {
    // Creating invisible container
    const outer = document.createElement("div");
    outer.style.visibility = "hidden";
    outer.style.overflow = "scroll"; // forcing scrollbar to appear
    document.body.appendChild(outer);

    // Creating inner element and placing it in the container
 const inner = document.createElement("div");
@livemehere
livemehere / I'm a night 🦉
Last active December 11, 2023 00:15
daily
🌞 Morning 106 commits █▋░░░░░░░░░░░░░░░░░░░ 8.1%
🌆 Daytime 350 commits █████▌░░░░░░░░░░░░░░░ 26.8%
🌃 Evening 393 commits ██████▎░░░░░░░░░░░░░░ 30.0%
🌙 Night 459 commits ███████▎░░░░░░░░░░░░░ 35.1%