Skip to content

Instantly share code, notes, and snippets.

@alanthai
alanthai / useReducer.ts
Created April 22, 2020 02:50
A more performant useReducer that only re-renders when the modified part of state is being read.
// example: https://stackblitz.com/edit/react-ts-hesbky?file=use-reducer.ts
// inspired by https://github.com/zeit/swr/pull/186/files
import {useState, useRef} from "react";
type StateDependencies<T> = {
[K in keyof T]?: boolean;
};
function equals(compareA, compareB) {
@alanthai
alanthai / setter.ts
Created June 4, 2020 17:06
Typesafe getter and setter
type Key = string | number | symbol
const PathSymbol = Symbol('path');
function pathProxy(path: Key[] = []) {
return new Proxy({
get [PathSymbol]() {
return path;
},
}, {
@alanthai
alanthai / input.scss
Created May 18, 2023 14:33
Generated by SassMeister.com.
:root {
--blitz-color-content-primary: #000000;
}
$blitz-color-content-primary: var(--blitz-color-content-primary, #000000);
$blitz-color-content-secondary: #000000;
.test {
background-color: $blitz-color-content-primary;
background-color: $blitz-color-content-secondary;