민프

[React][TypeScript] Clipboard API 를 이용하여서 붙여넣기를 해보자 본문

[React]

[React][TypeScript] Clipboard API 를 이용하여서 붙여넣기를 해보자

민프야 2023. 2. 28. 21:55

https://developer.mozilla.org/ko/docs/Web/API/Clipboard_API

 

Clipboard API - Web API | MDN

Clipboard API는 클립보드 명령(잘라내기, 복사, 붙여넣기)에 응답하거나 시스템 클립보드에 비동기적으로 접근하고 쓸 수 있는 기능을 제공합니다.

developer.mozilla.org

const eventKey = (e: React.KeyboardEvent<HTMLInputElement>) => {
    console.log("e", e);

    if (e.code === "Backspace" || e.key === "Backspace") {

      }
    } else if ((e.ctrlKey || e.metaKey) && e.key === "v") {
      navigator.clipboard
        .readText()
        .then((text) => {
    
        })
        .catch((err) => {
          console.error("Failed to read clipboard contents: ", err);
        });
    }
  };
Comments