How to copy text to clipboard in react-native?
You can use Clipboard
from @react-native-community.
Here's how you can use it:
import Clipboard from '@react-native-clipboard/clipboard';
<TouchableOpacity onPress={() => Clipboard.setString('[email protected]')}>
<View>
<Text style={{color: 'red', fontSize: 14 , fontFamily:'Arial', fontStyle: 'bold', textAlign: 'center', marginTop: 3, marginLeft: 25, marginBottom: 17}}>
[email protected]
</Text>
</View>
</TouchableOpacity>
Set selectable prop of the Text component true and the content will be copied to the clipboard with long press on the text.
<Text selectable={true}>
Your text
</Text>
fayeed is right. You can use clipboard for user to copy a string.
Also, you easily give your component a clipboard too. As fayeed did above
<Text
onPress={()=>Clipboard.setString('[email protected]')}
style={{color: 'red', fontSize: 14 , fontFamily:'Arial', fontStyle: 'bold', textAlign: 'center', marginTop: 3, marginLeft: 25, marginBottom: 17}}>
[email protected]
</Text>
import { Button, Clipboard } from 'react-native'
is replace with react-native-community/clipboard