Skip to content

Instantly share code, notes, and snippets.

View tawashichan's full-sized avatar

tawashichan tawashichan

View GitHub Profile
@voluntas
voluntas / webrtc.rst
Last active June 27, 2024 02:25
WebRTC コトハジメ
@hrdtbs
hrdtbs / react-hooks_exhaustive-deps.md
Last active October 10, 2023 09:36
メモ、なぜ`react-hooks/exhaustive-deps`はただcomponentDidMountのように使いたいだけなのに依存関係を入れてくるのか

なぜreact-hooks/exhaustive-depsはただcomponentDidMountのように使いたいだけなのに依存関係を入れてくるのか

export const Example = ({ loadOnlyOnce }) => {
    useEffect(() => {
      loadOnlyOnce()
    }, [loadOnlyOnce]) // ← WHY?
}
import { useEffect, useRef } from "react"
export const useOnClickOutside = <T extends HTMLDivElement>(handler?: (event: MouseEvent | TouchEvent) => void) => {
const ref = useRef<T>(null)
useEffect(() => {
const listener = (event: MouseEvent | TouchEvent) => {
if (handler) {
if (!ref.current || ref.current.contains(event.target as Node)) {
return
}
import { useEffect, useRef, useState } from "react"
interface UseResizeObserverReturns<T> {
ref: React.RefObject<T>
width: number
height: number
}
const useResizeObserver = <T>(): UseResizeObserverReturns<T> => {
const ref = useRef<T>(null)
const throttle = (callback) => {
let throttled = false
return () => {
if(throttled) return
throttled = true
window.setTimeout(()=>{throttled = false}, 500)
callback()
}
}
@hrdtbs
hrdtbs / useIntersectionObserver.ts
Last active February 13, 2022 23:28
React hooks of Observers
import { useLayoutEffect, useState } from "react"
let animationFrameID = 0
export const useIntersectionObserver = (
ref: React.RefObject<HTMLElement>,
options?: IntersectionObserverInit
): IntersectionObserverEntry | undefined => {
const [entry, setEntry] = useState<IntersectionObserverEntry>()
useLayoutEffect(() => {
const element = ref.current
@hrdtbs
hrdtbs / simple-suspence.js
Last active September 15, 2019 05:34
単純なReact.Suspenceの使用例
let done = false
const LazyComponent = () => {
if (!done) {
throw new Promise(resolve => {
window.setTimeout(() => {
done = true
resolve()
}, 3000)
})
}
@hrdtbs
hrdtbs / config.yml
Last active September 15, 2019 05:34
Specific Directory to Branch on CircleCI
workflows:
version: 2
hogehoge:
jobs:
- deploy:
filters:
branches:
only:
- master
version: 2
@hrdtbs
hrdtbs / install-github-repository.command
Last active September 15, 2019 05:34
Githubレポジトリをnpmでpackageとしてインストールする方法。Install repositories as npm package from github repository
# 構文
npm install github:[user|organization]/[repository]#[branch|tag|commit]
# 例文
npm install github:hrdtbs/hello-world#build
## *私が試した限りではbranch、tag、commitはorでした。要確認。
# セマンティックバージョニング
npm install github:[user|organization]/[repository]#semver:^X.Y.Z
@hrdtbs
hrdtbs / golang.circleci.config.yml
Last active September 15, 2019 05:33
Release & Lint & Test | Golang CircleCI
version: 2.1
executors:
golang:
docker:
- image: circleci/golang:latest
environment:
GO111MODULE: "on"
commands: