正常に遅延する
const debounced = useCallback(debounce((newValue) => myFunc(newValue), 300), [])
遅延しない ← valueが更新される度にdebounced
も更新されるため
const debounced = useCallback(debounce(() => myFunc(value), 300), [value])
正常に遅延する
const debounced = useCallback(debounce((newValue) => myFunc(newValue), 300), [])
遅延しない ← valueが更新される度にdebounced
も更新されるため
const debounced = useCallback(debounce(() => myFunc(value), 300), [value])
(例)hoge.comからpiyo.comのリソースを取得したい場合
訪れたことがなければpiyo.comのドメイン名からIPアドレスを調べる(DNSルックアップ)→piyo.comのサーバーとの接続を確立する(TCP ハンドシェイク ),HTTPSの場合は安全な通信の準備(TLS ネゴシエーション)も→リソースの取得といった順で行われる
詳しくは、https://developer.mozilla.org/ja/docs/Web/Performance/How_browsers_work
import { useForceUpdate } from "./useForceUpdate" | |
import { useLayoutEffect, useMemo, useRef } from "react" | |
interface Config extends RequestInit { | |
type?: "text" | "json" | "blob" | "formData" | |
auth?: string | |
} | |
export const useFetch = <T>(input: RequestInfo, config?: Config): [T, Error] => { | |
const forceUpdate = useForceUpdate() |
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# This script came about after I removed several big files from a GitHub | |
# repository (see https://gist.github.com/agarny/5541082) and force pushed | |
# everything back to GitHub. However, cloning the 'new' GitHub repository still | |
# results in those big files being present in the git history. This is, among | |
# other things, due to some pull requests I have in that repository and which | |
# reference those big files. I contacted GitHub about this, but there seems to | |
# be nothing that they can do about it. So, I was left with no other choice but |
import { useCallback, useEffect, useState } from "react" | |
interface BeforeInstallPromptEvent extends Event { | |
readonly platforms: Array<string> | |
readonly userChoice: Promise<{ | |
outcome: "accepted" | "dismissed" | |
platform: string | |
}> | |
prompt(): Promise<void> | |
} |
ほとんどの人は特に気にしなくいい機能。ただ記法が増えるので混乱しないように。
import type { SomeThing } from "./some-module.js";
export type { SomeThing };
type Nominal<T, K> = T & { | |
__name__: K; | |
} | |
type Unnominal<N> = Omit<N, '__name__'> | |
const makeNewNominal = <N>() => { | |
return (value: Unnominal<N> & { | |
__name__?: never; | |
}) => { |
import { render } from "react-dom" | |
import React, { Suspense, useState } from "react" | |
const LazyComponent = () => { | |
const [done, setDone] = useState(false) | |
if (!done) { | |
throw new Promise(resolve => { | |
window.setTimeout(() => { | |
console.log("inifinity!!!!!") | |
setDone(true) |
class Comparator { | |
constructor(compareFunction) { | |
this.compare = compareFunction || Comparator.defaultCompareFunction | |
} | |
static defaultCompareFunction(a, b) { | |
if (a === b) { | |
return 0 | |
} | |
return a < b ? -1 : 1 | |
} |