Install the library using either Yarn:
yarn add @react-native-clipboard/clipboard
or npm:文章来源:https://www.toymoban.com/news/detail-473728.html
npm install --save @react-native-clipboard/clipboard
import {Clipboard} from 'react-native';
or文章来源地址https://www.toymoban.com/news/detail-473728.html
import Clipboard from '@react-native-clipboard/clipboard';
Example
import React, {useState} from 'react'; import { SafeAreaView, View, Text, TouchableOpacity, StyleSheet, } from 'react-native'; import Clipboard from '@react-native-clipboard/clipboard'; const App = () => { const [copiedText, setCopiedText] = useState(''); const copyToClipboard = () => { Clipboard.setString('hello world'); }; const fetchCopiedText = async () => { const text = await Clipboard.getString(); setCopiedText(text); }; return ( <SafeAreaView style={{flex: 1}}> <View style={styles.container}> <TouchableOpacity onPress={copyToClipboard}> <Text>Click here to copy to Clipboard</Text> </TouchableOpacity> <TouchableOpacity onPress={fetchCopiedText}> <Text>View copied text</Text> </TouchableOpacity> <Text style={styles.copiedText}>{copiedText}</Text> </View> </SafeAreaView> ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, copiedText: { marginTop: 10, color: 'red', }, }); export default App;
到了这里,关于react-native-clipboard/clipboard使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!