Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added clipboard example #1604

Merged
merged 5 commits into from
Feb 18, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@ title: Clipboard

---


## Example

```SnackPlayer name=Clipboard%20API%20Example
brunokiafuka marked this conversation as resolved.
Show resolved Hide resolved
import React, { useState } from "react";
import { SafeAreaView, View, Text, TouchableOpacity, Clipboard } 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 (
<SafeAreaView>
<View>
<TouchableOpacity onPress={() => copyToClipboard()}>
<Text>Click here Copy to Clipboard</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => fetchCopiedText()}>
<Text>View copied text</Text>
</TouchableOpacity>
</View>

<Text>{copiedText}</Text>
</SafeAreaView>
);
};

export default App;
```

# Reference

## Methods
Expand Down