Challenge - 5 Problems
Sharing and Clipboard Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when this React Native clipboard code runs?
Consider this React Native code snippet that copies text to the clipboard and then reads it back to display in an alert. What will the alert show?
React Native
import Clipboard from '@react-native-clipboard/clipboard'; import {Alert} from 'react-native'; Clipboard.setString('Hello World'); Clipboard.getString().then(text => Alert.alert('Clipboard content', text));
Attempts:
2 left
💡 Hint
Clipboard.setString stores text, getString returns a Promise with that text.
✗ Incorrect
Clipboard.setString('Hello World') stores the string. Clipboard.getString() returns a Promise resolving to that string. The alert shows the stored text.
🧠 Conceptual
intermediate1:30remaining
Which React Native API is best for sharing text to other apps?
You want to let users share a text message from your app to other apps like email or messaging. Which React Native API should you use?
Attempts:
2 left
💡 Hint
Sharing means sending data to other apps, not just copying.
✗ Incorrect
The Share API opens the native share dialog letting users send text to other apps directly.
❓ lifecycle
advanced2:00remaining
What is the effect of calling Clipboard.getString() inside useEffect without dependencies?
In a React Native functional component, what happens if you call Clipboard.getString() inside useEffect with no dependency array?
React Native
import React, {useEffect} from 'react'; import Clipboard from '@react-native-clipboard/clipboard'; function MyComponent() { useEffect(() => { Clipboard.getString().then(text => console.log(text)); }); return null; }
Attempts:
2 left
💡 Hint
useEffect without [] runs after every render.
✗ Incorrect
Without a dependency array, useEffect runs after every render, so Clipboard.getString() is called repeatedly.
🔧 Debug
advanced2:00remaining
Why does this sharing code fail to open the share dialog?
This React Native code tries to share text but nothing happens. What is the likely cause?
React Native
import {Share} from 'react-native'; async function shareText() { try { await Share.share({message: 'Hello!'}); } catch (error) { console.error(error); } }
Attempts:
2 left
💡 Hint
Share.share returns a Promise that should be awaited.
✗ Incorrect
Without await, the Promise is not handled properly and the share dialog may not appear.
📝 Syntax
expert1:30remaining
What error does this clipboard code produce?
What error will this React Native clipboard code cause?
React Native
import Clipboard from '@react-native-clipboard/clipboard'; Clipboard.setString('Test'); Clipboard.getString().then(text => console.log(text));
Attempts:
2 left
💡 Hint
Check the signature of Clipboard.getString() in React Native.
✗ Incorrect
Clipboard.getString() returns a Promise and does not accept a callback, so passing a callback causes a TypeError.