Last active
March 1, 2019 09:17
-
-
Save michalchudziak/f99d403abe90f11e8146c6f75416a0c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* @flow */ | |
| import React, {useState, useEffect} from 'react'; | |
| import {NativeModules} from 'react-native'; | |
| export default function useClipboard() { | |
| const [contents, setContents] = useState(''); | |
| useEffect(() => { | |
| getClipboardContents(); | |
| }, []); | |
| const getClipboardContents = async () => { | |
| const content = await NativeModules.Clipboard.getString(); | |
| setContents(content); | |
| }; | |
| const setClipboardContents = (content) => { | |
| NativeModules.Clipboard.setString(content); | |
| setContents(content); | |
| }; | |
| return [contents, setClipboardContents]; | |
| }; |
Author
Good point @peterdev6, I'll update the contents.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you need to pass in an empty array as the second argument to
useEffectto make sure this effect only happens oncomponentDidMountandcomponentWillUnmount?