clipboard
clipboard copied to clipboard
Clipboard is null
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.
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.
I am with this issue too, but in the Native enviroment. Gonna try this too @Jorciney .
@Dheyson good luck!
@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)...
@lapico You are right, I'm not using Expo.
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.
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).
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
I solved it this way: cd android && ./gradlew clean
I solved it this way:
cd android && ./gradlew clean
This answer is the correct one. thank you!
Stil this is open?
I am still facing this issue. Any update on this?