diff --git a/docs/clipboard.md b/docs/clipboard.md index a0acaa08193..a4c92810c0f 100644 --- a/docs/clipboard.md +++ b/docs/clipboard.md @@ -7,6 +7,58 @@ title: Clipboard --- + +## Example + +```SnackPlayer name=Clipboard%20API%20Example&supportedPlatforms=ios,android + +import React, { useState } from 'react' +import { SafeAreaView, View, Text, TouchableOpacity, Clipboard, StyleSheet } from 'react-native' + +const App = () => { + const [copiedText, setCopiedText] = useState('') + + const copyToClipboard = () => { + Clipboard.setString('hello world') + } + + const fetchCopiedText = async () => { + const text = await Clipboard.getString() + setCopiedText(text) + } + + return ( + + + copyToClipboard()}> + Click here to copy to Clipboard + + fetchCopiedText()}> + View copied text + + + {copiedText} + + + + ) +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center' + }, + copiedText: { + marginTop: 10, + color: 'red' + } +}) + +export default App +``` + # Reference ## Methods