Appearance
getClipboardText
클립보드에 저장된 텍스트를 가져오는 함수예요. 복사된 텍스트를 읽어서 다른 작업에 활용할 수 있어요.
시그니처
typescript
function getClipboardText(): Promise<string>;
반환 값
- Promise<string>
클립보드에 저장된 텍스트를 반환해요. 클립보드에 텍스트가 없으면 빈 문자열을 반환해요.
예제
클립보드의 텍스트 가져오기
tsx
import React, { useState } from 'react';
import { View, Text, Button } from 'react-native';
import { getClipboardText } from '@apps-in-toss/framework';
// '붙여넣기' 버튼을 누르면 클립보드에 저장된 텍스트를 가져와 화면에 표시해요.
function PasteButton() {
const [text, setText] = useState('');
const handlePress = async () => {
try {
const clipboardText = await getClipboardText();
setText(clipboardText || '클립보드에 텍스트가 없어요.');
} catch (error) {
console.error('클립보드에서 텍스트를 가져오지 못했어요:', error);
}
};
return (
<View>
<Text>{text}</Text>
<Button title="붙여넣기" onPress={handlePress} />
</View>
);
}