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

Clipboard is null #80

Open
narkai opened this issue Nov 4, 2020 · 12 comments
Open

Clipboard is null #80

narkai opened this issue Nov 4, 2020 · 12 comments
Labels
bug Something isn't working

Comments

@narkai
Copy link

narkai commented Nov 4, 2020

Environment

React Native with Expo 39

Platforms

Android

Versions

  • Android: 10
  • react-native: 63

Description

...

import Clipboard from '@react-native-community/clipboard';

...

const Component = () => {

  useEffect(() => {
    const check = async () => {
      const clipboard = await Clipboard.getString();
      if (clipboard) {
        setClipboard(clipboard);
        Clipboard.setString('');
    };
    check();
  }, []);

...

This code throws this error: null is not an object (evaluating 'NativeClipboard_1.default.getString')

But strangely, when I test the code with Jest it works... Maybe Clipboard is not yet mounted properly when the effect is triggered.

@narkai narkai added the bug Something isn't working label Nov 4, 2020
@Jorciney
Copy link

Jorciney commented Nov 7, 2020

I had the same issue with Android.
Weird enough I had to do a pod install:
cd ios && pod install && cd ../
after that, I ran react-native run-android and it worked.

@dheysonalves
Copy link

dheysonalves commented Nov 10, 2020

I am with this issue too, but in the Native enviroment. Gonna try this too @Jorciney .

@Jorciney
Copy link

@dheyson good luck!

@narkai
Copy link
Author

narkai commented Nov 11, 2020

@Jorciney are you using React Native with Expo (managed project) ?

Unfortunately I think it's not recommended to use pod install with Expo (managed project)...

@Jorciney
Copy link

@Lapico You are right, I'm not using Expo.

@roshnet
Copy link

roshnet commented Nov 22, 2020

Seems like using the native alternative (deprecated) is the only workaround for now. The community version just doesn't work with Expo. I tried a lot, including using useClipboard hook, but have to now settle with using the deprecated version. At least it doesn't throw that ugly error.

@narkai
Copy link
Author

narkai commented Nov 23, 2020

I confirm this, I also use the deprecated version because the community one does not work with Expo.

Strange fact, the community version seemed to work in the tests (Jest).

@Naturalclar
Copy link
Member

Unfortunately, this module is not compatible with Expo, since expo only works with preinstalled native modules. If you're using Expo with managed workflow, please use the Clipboard module exported from react-native

@iqorlobanov
Copy link

I solved it this way: cd android && ./gradlew clean

@BiYuqi
Copy link

BiYuqi commented Nov 3, 2021

I solved it this way: cd android && ./gradlew clean

This answer is the correct one. thank you!

@ajstharsan-radus28
Copy link

Stil this is open?

@kunalsolanki1992
Copy link

I am still facing this issue. Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants