Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<style>
@keyframes cursorBlink {
0% {
border-right-color: initial;
@ZacharyL2
ZacharyL2 / useUrlState.ts
Created March 26, 2023 14:06
Simple useUrlState
import { useMemo, useRef } from 'react';
import { useLocation, useNavigate } from 'react-router';
const useUrlState = <S extends Record<string, string>>(
initialState: S,
navigateMode: 'push' | 'replace' = 'push',
) => {
const location = useLocation();
const navigate = useNavigate();
import { useEffect, useRef, useState } from 'react';
type RotatedImage = {
src: string;
width: number;
height: number;
} | null;
let canvas: HTMLCanvasElement | null = null;
let canvasCtx2D: CanvasRenderingContext2D | null = null;
import { useEffect, useRef } from 'react';
const usePrevious = (value) => {
const ref = useRef();
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
import { useEffect, useState } from 'react';
const Router = ({ routes, defaultComponent }) => {
const [currentPath, setCurrentPath] = useState(
() => window.location.pathname,
);
useEffect(() => {
const onLocationChange = () => {
setCurrentPath(window.location.pathname);
console.time('Time');
const fs = require('fs');
const readline = require('readline');
void (async () => {
const rl = readline.createInterface({
input: fs.createReadStream('test.json'),
crlfDelay: Infinity,
});
<custom-button backgroundColor="red"></custom-button>
<script>
const template = `
<style>
button {
background-color: blue;
color: #fff;
}
</style>
display: none visibility: hidden opacity: 0
Remove from document flow Y N N
Reflow Y N N
Repaint Y Y /
Reversed on child element N Y N
transition N Y Y
Self-attached events are triggerable N N Y
const enum StepKey {
next = 'next',
throw = 'throw',
}
const generator2async = <
P extends any[],
T = unknown,
TReturn = any,
TNext = unknown,
// Serial execution of multiple functions
const compose = (...funcs) =>
funcs.reduce(
(a, b) =>
(...args) =>
a(b(...args)),
);
export const createStore = (reducer, enhancer) => {
if (typeof enhancer === 'function') {