Skip to content

Instantly share code, notes, and snippets.

View kuwabataK's full-sized avatar

KuwabataK kuwabataK

View GitHub Profile
@kuwabataK
kuwabataK / UseReducerTest.tsx
Created November 25, 2019 16:20
useReducerの型定義例です
import React, { useReducer } from "react";
import "./App.css";
const initialState = { count: 0, str: "" };
type ActionTypes =
{
type: "increment";
payload: { num: number };
}
class User {
userId: number = 0
userName: string = ""
}
const user1: User = {
userId: 1,
userName: "user1"
}
@kuwabataK
kuwabataK / asyncSetTimeout.js
Last active August 17, 2019 05:15
cancelable Promise setTimeout() sample
function asyncSetTimeout(msec, func = () => {}){
let timeoutId
let r
const exec = () => new Promise((res) => {
r = res
timeoutId = setTimeout(async () => {
timeoutId = null
await func()
res()