Skip to content

Instantly share code, notes, and snippets.

View Dearest's full-sized avatar

Dearest Dearest

View GitHub Profile
@Dearest
Dearest / gist:6c6129f155311e3ed168faa5d1f1e758
Created February 16, 2022 07:59 — forked from xfyuan/gist:a290fbd885af75fba742b4267a1ea23d
Create GitLab Merge Request from terminal
We couldn’t find that file to show.
import { noop } from '../utils';
function copy(text) {
if (navigator.clipboard) {
return navigator.clipboard.writeText(text).catch((error) => {
throw error !== undefined
? error
: new DOMException('The request is not allowed', 'NotAllowedError');
});
}
import { useEffect, useCallback, useRef } from 'react';
export default function useDebounce(callback, wait) {
const timer = useRef();
const cancel = useCallback(() => {
if (timer.current) {
clearTimeout(timer.current);
}
import { useEffect, useCallback, useRef } from 'react';
export default function useThrottle(callback, wait, { immediate = false } = {}) {
const timer = useRef();
const inThrottle = useRef(false);
const cancel = useCallback(() => {
if (timer.current) {
clearTimeout(timer.current);
}
import { useEffect, useRef } from 'react';
export default function usePreviousValue(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
import {
useState, useRef, useEffect,
} from 'react';
import { useRouter } from 'next/router';
import { useEventCallback } from '@material-ui/core/utils';
export default function usePageRefresh(callback, { skip } = {}) {
const router = useRouter();
const [refreshing, setRefreshing] = useState(false);
const currentAsPath = useRef();
import { useState } from 'react';
export default function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(() => {
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
return initialValue;
}
import { useRef, useCallback, useEffect } from 'react';
import useEventListener from './use-event-listener';
const keyCodeAliasMapping = {
esc: 27,
tab: 9,
enter: 13,
space: 32,
up: 38,
left: 37,
import { useRouter } from 'next/router';
import { openMiniProgramSchema } from '@/modules/utils';
let basePage = {};
export default function useFullscreenLayout() {
const router = useRouter();
const handleRouteChange = (url) => {
if (url === basePage.asPath) {
import { useEffect, useRef } from 'react';
function getElement(element) {
return typeof element === 'function' ? element() : element;
}
export default function useEventListener(
element, eventName, handler, { skip = false, ...options } = {},
) {
const handlerRef = useRef();