useStateã®å useStateã®ç¶æ
管çé¢æ°ãPropsã§æž¡ããšããåãåãåŽã¯
Dispatch<SetStateAction<T>>; ãšããæ¹ã§åãåãããšã«ãªãã
ãžã§ããªã¯ã¹ã®ã¡ãªãããããŸãã¡ é¢ä¿ãªããã©ãã£ãšæ°ã«ãªã£ãŠããããžã§ããªã¯ã¹ã®ã¡ãªãããããŸãã¡ãã³ãšããªã件ãã«ã€ããŠãã€ãã§ã«èª¿ã¹ãŠã¿ãããšã«ããã
äŸãã°ã
// æååãå
¥åããæååãåºåããé¢æ° const returnText = (input: string): string => { return input; }; // æ°å€ãå
¥åããæ°å€ãåºåããé¢æ° const returnNumber = (input: number): number => { return input; }; console.log(returnText("hello world"), "returnText"); console.log(returnNumber(0), "returnNumber"); ãšããé¢æ°ãååšããæã
const returnTextOrNumber = (input: string | number): string | number => { return input; }; console.log(returnTextOrNumber("hello world"), "returnTextOrNumber"); console.log(returnTextOrNumber(0), "returnTextOrNumber"); ãããªæãã«ãŸãšããããªãã
ããããžã§ããªãã¯åã«ãããšã
const returnTextOrNumberGeneric = <T extends string | number>(input: T): T => { return input; }; ãããªæãã«ãªãã...