๐Ÿšจ Type โ€˜KeyboardEventโ€™ is not generic.

๐Ÿšจ ์—๋Ÿฌ ๋ฐœ์ƒ

KeyboardEvent๋ฅผ ์“ฐ๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

const onPressEnter = useCallback(
  async (e: KeyboardEvent<HTMLInputElement>) => {
    // Error. Type 'KeyboardEvent' is not generic.ts
    if (e.key === "Enter" && !isUserValidation) {
      await onClickSignIn();
    }
  },
  [isUserValidation]
);

์•ž์— React.๋ฅผ ๋ถ™์ด๋ฉด ํ•ด๊ฒฐ ๋์ง€๋งŒ, ๋‹ค๋ฅธ ์ด๋ฒคํŠธ๋ฅผ ์“ธ ๋•Œ๋Š” ํ‰์†Œ์ฒ˜๋Ÿผ ๊ทธ๋ƒฅ ์“ฐ์—ฌ์„œ ๊ถ๊ธˆํ•ด์„œ ์ฐพ์•„๋ดค๋‹ค.

โ” ์—๋Ÿฌ ์›์ธ

์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋˜ ์ด๋ฒคํŠธ๊ฐ€ React๊ฐ€ ์•„๋‹Œ DOM์—์„œ ๊ฐ€์ ธ์™€์„œ ์ƒ๊ธด ์—๋Ÿฌ์˜€๋‹ค. ์ฝ”๋“œ์˜ import์„ ๋ดค๋”๋‹ˆ KeyboardEvent๋งŒ ๋น ์ ธ์žˆ์—ˆ๋‹ค.

import { ChangeEvent, useMemo, useState } from "react";

๐Ÿ”จ ์—๋Ÿฌ ํ•ด๊ฒฐ

KeyboardEvent๋ฅผ React์—์„œ impotํ•ด์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ๋ณ€๊ฒฝํ•ด์ฃผ์—ˆ๋‹ค.

import { ChangeEvent, KeyboardEvent, useMemo, useState } from "react";

์ฐธ๊ณ 

Leave a comment